0

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

8
  • 1
    Where are you stuck on using one of the many commands Microsoft Provides for copying files? Robocopy, Xcopy, and just Copy. To delete a file use the DEL command. Please take the tour. Please read How to Ask a good question. Then provide a minimal reproducible example of the code you are trying to use to solve your problem. Commented Jul 28, 2021 at 13:19
  • @Squashman noted man i updated the details above Commented Jul 28, 2021 at 13:30
  • The FOR /F command you are using reads the contents of a file and for each line it reads it assigns the output of the line to the FOR meta-variable %%I. Why are you doing that? You made no mention of using a file as the source for what files you want to copy. You also made no mention of copying these files from subdirectories and the XCOPY code is doing so. Commented Jul 28, 2021 at 13:47
  • @Squashmanh hello in above inquiry mentioned: I only want to copy the ff files: 123.CSV 456.CSV 678.CSV 012.CSV Source Folder: "G:\SOURCE\123%%I" Basically i want to copy only 10 CSV files from source folder, however that folder has 100 Plus .CSV file. Commented Jul 28, 2021 at 14:18
  • So what is stopping you from just doing a simple brute force with 10 XCOPY commands? xcopy "G:\SOURCE\123.csv" "G:\DESTINATION\". Rinse and repeat. Commented Jul 28, 2021 at 14:28

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.