Search code examples
batch-filebatch-processingxcopy

Batch File Xcopy specific file only


Would like to seek your help on creating simple bat file that will copy specific file from source to destination. Eg.

Source = C:\Source
Dest = D:\Destination

File in source:

123.CSV
234.CSV
456.CSV
567.CSV
678.CSV
789.CSV
012.CSV

and I only want to copy the ff:

123.CSV
456.CSV
678.CSV
012.CSV

and delete others after copying.

Script:

@ECHO OFF

CHCP 65001 > NUL


FOR /F "usebackq delims=" %%I IN ("G:\SOURCE\123.CSV") DO (
    xcopy /s "G:\SOURCE\123%%I" "G:\DESTINATION\%%I*"
)

PAUSE

Thank you for your help in advance


Solution

  • This works fine. Or one big long ROBOCOPY command. robocopy "G:\SOURCE" "G:\DESTINATION" "123.CSV" "456.CSV" "678.CSV" "012.CSV" – @squashman