Let's not forget good old parameters. When starting your *.bat or *.cmd file you can add up to nine parameters after the command file name:
call myscript.bat \\path\to\my\file.ext type
call myscript.bat \\path\to\my\file.ext "Del /F"
The myscript.bat could be something like this:
@Echo Off
Echo The path of this scriptfile %~0
Echo The name of this scriptfile %~n0
Echo The extension of this scriptfile %~x0
Echo.
If "%~2"=="" (
Echo Parameter missing, quitting.
GoTo :EOF
)
If Not Exist "%~1" (
Echo File does not exist, quitting.
GoTo :EOF
)
Echo Going to %~2 this file: %~1
%~2 "%~1"
If %errorlevel% NEQ 0 (
Echo Failed to %~2 the %~1.
)
@Echo On
c:\>c:\bats\myscript.bat \\server\path\x.txt type
The path of this scriptfile c:\bats\myscript.bat
The name of this scriptfile myscript
The extension of this scriptfile .bat
Going to type this file: \\server\path\x.txt
This is the content of the file:
Some alphabets: ABCDEFG abcdefg
Some numbers: 1234567890
c:\>c:\bats\myscript.bat \\server\path\x.txt "del /f "
The path of this scriptfile c:\bats\myscript.bat
The name of this scriptfile myscript
The extension of this scriptfile .bat
Going to del /f this file: \\server\path\x.txt
c:\>