I seem to be stuck with a batch script and would like some help.
Basically I need to check if a file exists in a folder in the %localappdata%
and if it does then overwrite the file and if not place inside a different location so at the moment it reads like this:
IF EXIST "%localappdata%\foldername\filename" COPY /Y "filename" "location" ELSE COPY "filename" "location2"
But when this runs I'm receiving an error of The syntax of the command is incorrect.
This seems to be down to the %localappdata%
variable being used.
Thank you in advance for any help on this.
You need to put the two commands for the IF
branches in parens:
IF EXIST "%localappdata%\foldername\filename" (COPY /Y "filename" "location") ELSE (COPY "filename" "location2")
The reason for this is that the shell needs to be able to tell that if the file does exist, the command you want to run is just this:
COPY /Y "filename" "location"
and not all of this:
COPY /Y "filename" "location" ELSE COPY "filename" "location2"
If you think about it, all those ELSE COPY
stuff may very well be legitimate parameters for the first COPY
-- the shell has no way to know unless you help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With