Reputation: 1
I don't have any problem to do Xcopy, but the source folder may be not the one specified. It could be one among three folders.
So I would like a proceed that
set sourcefolder = "folder1"
if not exist set sourcefolder = "folder2"
if not exist set sourcefolder = "folder3"
if not exist exit
But I'm a newbie in scripting, so I would be glad if anyone could help me please.
Upvotes: 0
Views: 576
Reputation: 34909
There are some issues in your code:
=
in a set
command line, because set sourcefolder = path
assigns SPACEpath
to the variable sourcefolder
SPACE;set
syntax set "sourcefolder=C\MyFolder"
; the quotes ""
do not become part of the variable value here, so place them when expanding (reading) the variable like "%sourcefolder%"
;if not exist
you need to specify what to check, like if not exist "%sourcefolder%"
;exit /B
rather than exit
as the latter terminates also the command prompt (cmd
) instance;Here is the fixed code:
set "sourcefolder=C:\MyFolder"
if not exist "%sourcefolder%" set "sourcefolder=D:\MyFolder"
if not exist "%sourcefolder%" set "sourcefolder=E:\MyFolder"
if not exist "%sourcefolder%" (
echo Could not find a valid source folder.
exit /B
)
xcopy /E /I /Y "%sourcefolder%" "V:\Save\"
Upvotes: 1