DOS moving specific .xml file extension [duplicate]
As @Scott's link discusses, *.xml
matches *.xml_
, because the 8.3 name ends in .XML
(use dir /x
to show).
Fortunately, the ForFiles command is not subject to this eccentricity, so you can use:
forfiles /m *.xml /c "cmd /c move @path TargetDir\"
Notes:
- Because
move
is an internal command, a separatecmd
is needed to invoke it (this would not be needed with an external command (such asxcopy
), as inforfiles /m *.xml /c "xcopy @path TargetDir\"
). -
There is a
/s
option, which will recurse through subdirectories, but it will not recurse the target directory: if you want the source tree to be matched at the target, you will need to parse the source path in order to find the correct target directory, which is probably best done in a batch file:forfiles /m *.xml /c "cmd /c call mover.cmd @relpath TargetDir\"
Should you need
mover.cmd
, I'll leave writing it as a scripting exercise for you.- I haven't tested what happens when there are spaces in the file or directory names, but I would expect complications.