Archive for September, 2014

dos batch copy directory contents with wild card

Sunday, 28 September 2014

If you want to use xcopy in a batchfile to mirror the contents of some other path with a wildcard expression, instead of dumping all the files into your current working directory, this may be what you need:

for /D %%I in (%1) do xcopy “%%I” “%%~nI” /S /I

If you think of the fully qualified pathname as a slash-delimited stack, the ~n operator pops the last element from it and uses it as the target parameter for xcopy. If you put this in a batchfile called, say, copys, you can use like so:

copys d:\some\network\path\backup*

and your current working directory will get the backup* directories and their contents.