I have a batch file that setups something I made. In the batch file I have a variable called OriginalFileName and set it to ProgramSetup,

set OriginalFileName=ProgramSetup

I want to know how to import the current filename of the batch file to CurrentFileName to later on check if the filename was changed or not with:

if "%CurrentFileName%" EQU "%OriginalFileName%" goto :anything

if not .... [other actions]

So my question is: How to import the current filename of a batch file to a variable when the batch file is running.

  • Do you really mean 'when the batch file is running'? Could you not check this at the start?
    – Daniel K
    May 27 '19 at 17:16

You can use %0 for the current script, or more commonly:

  • %~dp0 for the drive:\path,
  • %~nx0 for the filename.ext
  • Thanks, I will check it when I get to my Laptop.
    – Ali
    May 27 '19 at 14:32
  • grawity is correct - learning about arguments opens up a whole bunch of different options when you're working through cmd.exe and batch; definitely worth exploring.
    – mael'
    May 27 '19 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.