Keep in mind that 0 is a special case of parameter numbers inside a batch file, where 0 means this file, as indicated on the command line.
So, if the file is myfile.bat, you can name it in several ways as follows, each of which will give you a different result of using% 0 or% ~ 0:
Myfile
myfile.bat
MYDIR \ myfile.bat
C: \ MYDIR \ myfile.bat
"C: \ MYDIR \ myfile.bat"
All of the above is a legal challenge if you call it from the correct relative location in the directory in which it exists. % ~ 0 breaks the quotes from the last example, while% 0 does not.
Since they all give different results,% 0 and% ~ 0 are unlikely to be what you really want to use.
Here is the batch file to illustrate:
@echo Full path and filename: %~f0 @echo Drive: %~d0 @echo Path: %~p0 @echo Drive and path: %~dp0 @echo Filename without extension: %~n0 @echo Filename with extension: %~nx0 @echo Extension: %~x0 @echo Filename as given on command line: %0 @echo Filename as given on command line minus quotes: %~0 @REM Build from parts @SETLOCAL @SET drv=%~d0 @SET pth=%~p0 @SET fpath=%~dp0 @SET fname=%~n0 @SET ext=%~x0 @echo Simply Constructed name: %fpath%%fname%%ext% @echo Fully Constructed name: %drv%%pth%%fname%%ext% @ENDLOCAL pause
Jool Nov 11 '15 at 17:15 2015-11-11 17:15
source share