How to use multiple commands in batch using forfiles command?
The two commands have absolutely nothing in common, so no, you cannot use parentheses like that.
You must execute all the commands within a single CMD /C. You can concatenate commands on one line using &
. I've defined a simple XCOPY "macro" to save a bit of typing.
set XCOPY=xcopy /e /c /h /i /v /r /y /q"
forfiles /m "%worldprefix%*" /c "cmd /c echo Copying World: @path&%XCOPY% @file %snapshotdir%\@file\%itdate%-%hour%-%time:~3,2%-%time:~6,2%&%XCOPY% @file %backdir%\%itdate%D\worlds\@file"
If you escape the quotes, then you can use line continuation to split the logical line accross multiple lines. But then you must also escape the &
.
set XCOPY=xcopy /e /c /h /i /v /r /y /q"
forfiles /m "%worldprefix%*" /c ^"cmd /c ^
echo Copying World: @path ^&^
%XCOPY% @file %snapshotdir%\@file\%itdate%-%hour%-%time:~3,2%-%time:~6,2% ^&^
%XCOPY% @file %backdir%\%itdate%D\worlds\@file^"
Or you could put the &
in the front of the line so that you don't need to escape it. The line continuation also escapes the first character of the next line:
set XCOPY=xcopy /e /c /h /i /v /r /y /q"
forfiles /m "%worldprefix%*" /c ^"cmd /c ^
echo Copying World: @path^
&%XCOPY% @file %snapshotdir%\@file\%itdate%-%hour%-%time:~3,2%-%time:~6,2%^
&%XCOPY% @file %backdir%\%itdate%D\worlds\@file^"
I realize this is an old post, but another way of doing it is to call a batch file and pass it the parameters that it needs. And I do not believe that there is any limitations in what can be in that batch file. For example:
forfiles /M "*.img" /C "cmd /c ProcessFile.bat @file @fdate @ftime"