i have this instruction in the batch file:
for /f "tokens=1,2,* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo. %%B %%C
i want to know what's the function of this command: %~f0
what is %~f0
Moderator: DosItHelp
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
To expand on DosItHelp . . .
call /? will show you what the parameters are that you can use.
%1, %2 you're probably familiar with as the 1st, 2nd parameter that you can pass to a script file. Well, %0 is the actual command that you call.
From the help screen: %~fN (where N is the parameter on the command line you're interested in) "expands %N to a fully qualified path name". This is actually the full path and file name -- regardless of how the file was actually called. Example:
If I'm in the c:\tmp directory and I execute the following command:
Then the following will be defined:
%~f0 evaluates to c:\tmp\test.cmd
%~f1 evaluates to c:\windows\file.txt
%~f2 evaluates to c:\tmp\file.txt
%~f3 evaluates to c:\file.txt
%~f4 evaluates to c:\program files\file.txt NOTE THERE ARE NO QUOTES
%~f5 evaluates to c:\tmp\a file.txt (still NO QUOTES)
The files don't actually have to exist.
call /? will show you what the parameters are that you can use.
%1, %2 you're probably familiar with as the 1st, 2nd parameter that you can pass to a script file. Well, %0 is the actual command that you call.
From the help screen: %~fN (where N is the parameter on the command line you're interested in) "expands %N to a fully qualified path name". This is actually the full path and file name -- regardless of how the file was actually called. Example:
If I'm in the c:\tmp directory and I execute the following command:
Code: Select all
test.cmd c:\windows\file.txt .\file.txt ..\file.txt "c:\program files\file.txt" "a file.txt"
Then the following will be defined:
%~f0 evaluates to c:\tmp\test.cmd
%~f1 evaluates to c:\windows\file.txt
%~f2 evaluates to c:\tmp\file.txt
%~f3 evaluates to c:\file.txt
%~f4 evaluates to c:\program files\file.txt NOTE THERE ARE NO QUOTES
%~f5 evaluates to c:\tmp\a file.txt (still NO QUOTES)
The files don't actually have to exist.