user198989
user198989

Reputation: 4665

Copying bat file (itself) to appdata

I'm trying to make the bat copy itself to appdata folder. I have tried this

copy %0 "%appdata%\windows.bat" > nul

But it doesn't copy itself. What is the correct way to do that ?

Upvotes: 1

Views: 168

Answers (1)

npocmaka
npocmaka

Reputation: 57282

@copy "%~f0" "%appdata%\windows.bat" > nul

Do you have spaces in the file name? If yes this will require your file name to be put in double quotes.

Have you used the CD or PUSHD command? If yes you'll need to use full path instead of relative (with %~f).

have you used SHIFT command somewhere in the script? This can change the %0 value.

Upvotes: 1

Related Questions