Answer by Fred Tusing for Can a Windows batch file determine its own file name?
Below is my initial code: @echo off Set z=%% echo. echo %z%0.......%0 echo %z%~0......%~0 echo %z%n0......%n0 echo %z%x0......%x0 echo %z%~n0.....%~n0 echo %z%dp0.....%dp0 echo %z%~dp0....%~dp0 echo. I...
View ArticleAnswer by Cary for Can a Windows batch file determine its own file name?
Try to run below example in order to feel how the magical variables work. @echo off SETLOCAL EnableDelayedExpansion echo Full path and filename: %~f0 echo Drive: %~d0 echo Path: %~p0 echo Drive and...
View ArticleAnswer by Jool for Can a Windows batch file determine its own file name?
Bear in mind that 0 is a special case of parameter numbers inside a batch file, where 0 means this file as given on the command line. So if the file is myfile.bat, you could call it in several ways as...
View ArticleAnswer by JustJeff for Can a Windows batch file determine its own file name?
You can get the file name, but you can also get the full path, depending what you place between the '%~' and the '0'. Take your pick from d -- drive p -- path n -- file name x -- extension f -- full...
View ArticleAnswer by djangofan for Can a Windows batch file determine its own file name?
Using the following script, based on SLaks answer, I determined that the correct answer is: echo The name of this file is: %~n0%~x0 echo The name of this file is: %~nx0 And here is my test script:...
View ArticleAnswer by SLaks for Can a Windows batch file determine its own file name?
Yes. Use the special %0 variable to get the path to the current file. Write %~n0 to get just the filename without the extension. Write %~n0%~x0 to get the filename and extension. Also possible to write...
View ArticleCan a Windows batch file determine its own file name?
Can a Windows batch file determine its own file name? For example, if I run the batch file C:\Temp\myScript.bat, is there a command within myScript.bat that can determine the string "myScript.bat"?
View Article
More Pages to Explore .....