I want my batch file to echo its filename into a text document.
I tried:
echo %~f0>"%userprofile%\Desktop\test\test.txt"
But instead of saying only its filename, it also says the directory that it's in.
C:\Users\User\Desktop\test.bat
I want my batch file to echo its filename into a text document.
I tried:
echo %~f0>"%userprofile%\Desktop\test\test.txt"
But instead of saying only its filename, it also says the directory that it's in.
C:\Users\User\Desktop\test.bat
Use %~n0
or %~nx0
in place of %~f0
depending on what your interpretation of name
is.
See
for /? |more
from the prompt for documentation
To get the filename and extension, use %~nx0
. For a complete list of variable references, see for /?
For example:
echo %~nx0 > "%userprofile%\Desktop\test\test.txt"
Would output:
test.bat