Reputation: 63
I have written an small batch file that moves all content from one folder to another. This works fine. However, the source folder contains two types of files. One of the types is .doc and the other is .xml. Both files have the same name. But sometimes, one of the files (either .doc or .xml) is missing.
@echo off
move /y "\\networklocation\folder\folder\*.*" "M:\localfolder"
The question is how to make my script move only couples of .doc and .xml files that have the same name. For example, the source contains 1.doc, 2.doc and 1.xml. The script should only move 1.doc and 1.xml. 2.doc should stay in the source folder.
I've looked for this particular problem but have not found really anything.
Upvotes: 0
Views: 5402
Reputation: 37569
Try this:
@echo off &setlocal
for %%i in ("\\networklocation\folder\folder\*.doc") do (
if exist "%%~dpni.xml" (
move /y "%%~i" "M:\localfolder"
move /y "%%~dpni.xml" "M:\localfolder"
)
)
Upvotes: 2