BAT file XCOPY (or ROBOCOPY) to search subdirectories for files with similar names & copy to one folder

Mike_K007 1 Reputation point
2022-06-14T21:28:57.243+00:00

Searched all over but can only find fragmented pieces that I can't seem to get to work.

I am looking to create a .bat file which will use XCOPY (or ROBOCOPY) to search within folder H:\projects (and search all subfolders within this folder) for any files containing *_Checklist.xlsm and copy all of these files to C:\reports.

Is there a way to do this with XCOPY or ROBOCOPY in a bat file?

Thanks!

Windows 10 Network
Windows 10 Network
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Network: A group of devices that communicate either wirelessly or via a physical connection.
2,379 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,786 Reputation points
    2022-06-15T15:24:31.013+00:00

    Hi MikeK007-2413,

    If you want to use xcopy:

    xcopy /s foo???.txt g:\someplace
    This will hold the directory structure.

    If you don't want the directory structure you can do the following:

    for /r %i in (foo???.txt) do xcopy /Y "%i" g:\someplace
    If you are using this in a batchfile you should double the % like this:

    for /r %%i in (foo???.txt) do xcopy /Y "%%i" g:\someplace

    This is an excellent guide to copy:

    https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy

    I hope this answers your question.

    ---------------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.