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”?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes.
Use the special
%0variable to get the path to the current file.Write
%~n0to get just the filename without the extension.Write
%~n0%~x0to get the filename and extension.Also possible to write
%~nx0to get the filename and extension.