Batch scenario: what is the difference between% 0 and% ~ f0?

I have a script package in which I want to get the full path to the script. I am curious if there is a difference between this:

set scriptpath=%0

and this:

set scriptpath=%~f0

Thanks for the help.

+4
source share
2 answers

%0 refer argument 0 - the name of the batch file - always exactly the same as specified on the command line or in another batch file.

So, if a batch file with the name Test.batstored in C:\Tempis launched, for example, from a command window with the current directory C:\c temp\test, then the link %0is replaced with temp\teston.

%~f0 - , 1 , &()[]{}^=;!'+,`~ .

Test.bat C:\Temp

@echo %0
@echo %~f0

"temp\test.bat" C:\:

"temp\test.bat"
C:\Temp\Test.bat

:

  • ,
  • .

%~f0 CALL call /? FOR for /? .

1:

, , CD PUSHD. . ~ dp0 .

2:

C:\ "temp\test" :

"temp\test"
C:\Temp\Test

, , . temp\test :

temp\test
C:\Temp\Test.bat
+5

%~f0 %0 . , %0.

For.

+4

All Articles