I'm attempting to standardize a portion of the copying in a script I was given.
Because of this it would be nice to re-write the following block:
REM Copy files
for %%x in (%var1%) do (
copy %src%\%%x %dest%\%%x
)
where var1
contains strings in the format folder\folder\file.fileExtension
, so an example would be:
var1=test\test1\test1.txt test\test1\test2.txt test\test3\randomfile.cmd
The destination doesn't exist yet (currently it's just created separately).
Unfortunately robocopy
won't copy this way (It won't accept the format folder\file
and folder\file
as source and destination from what I've seen). This means I need to either break the variable at the last backslash into two variables or use a different copy tool (like copy
or xcopy
), but this is "discouraged".
Does anyone have a clever way of getting robocopy
to accept this format without creating a new function to break the passed variable into two new variables? Or is there a different way to store an iterable list of folder\file
paths that would remove this issue?
I've been able to retrieve the name portion from the passed parameter given %%~n
but am unable to retrieve the path portion of the passed parameter as it's not a full path. I attempted to use a for
loop to just cut that portion off (similar to results here: Last token in batch variable)
That doesn't work as it's a \
deliminated string, and as far as I know you can't cycle through in FOREACH style in for /f
.