i have a batch file that should work in multiple directories:
it should look for a file called "folder.jpg". If existant, it should use that. if not exist, it should use "front.jpg" and copy it to "cover.jpg". Sounds simple.
The problem is, that my directories contain whitespaces ( - ).
The following batch file produces an error. Can anyone direct me, how to get a filename that can be used with "EXISTS" batch command?
I also tried "./folder.jpg" with no success.
@echo off
set file=%CD%\folder.jpg
set
if exists %file% goto FOLDER
:FRONT
@echo ** copy front.jpg to cover.jpg
copy front.jpg cover.jpg
goto PROCESS
:FOLDER
@echo ** rename folder.jpg to cover.jpg
ren folder.jpg cover.jpg
:PROCESS
@echo ** call dpi
call dpi
@echo ** call size
call sizeThanks in advance!
11 Answer
Your main problem is that the syntax is IF EXIST filename (that is, no 's'). When file and folder names have spaces, use quote marks.
set file="%CD%\folder.jpg"if exist %file% goto FOLDER
or...
set file=%CD%\folder.jpgif exist "%file%" goto FOLDER
Also, did you really want the bare set command in the third code line? It looks a bit lonely all by itself.
Finally, if you have @echo off at the start of the script, you don't need to put the @ symbol at the start of every echo command.