English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Maybe %myname% or somthing.Im puting a command in my batchfile that makes the batchfile copy itself to system32 directory.But right now I am doing (Xcopy ".\daves.bat" "c:\windows\system32").It works but I would like this batchfile to be more universal so I can change the name and have it still work mainly because I convert the batch to an exe which will make the name daves.exe and it wont copy.Thanks

2007-06-02 00:03:50 · 1 answers · asked by Anonymous in Computers & Internet Other - Computers

1 answers

Yes, there is an easy way to do this. By default, the name of the batch file is automatically stored as the %0 (that's a zero) variable.

To test, try the following code snippet in a batch file.

===========

@echo off
cls
echo The name of this batch file is: %0

===========

Important Note:
This %0 nameholder variable stores the name of the file in the format that you call it. Meaning, if you call your batch file without using the ".bat" extension, then %0 will hold "daves". If you call your batch file using the extension, then %0 will hold "daves.bat"

2007-06-03 10:49:13 · answer #1 · answered by Kevin 7 · 5 0

fedest.com, questions and answers