Search code examples
cmdgrepcopyfindstr

Command line copy all network folder files of a specific name pattern including those files in subfolders


I want to use command line to copy all files from a network folder to my local machine.

I only want to copy files that have a specific name string pattern.

The files may be located in different folders or subfolders.

For example, if we have the following files:

//networkfolder/subfolder1/213123_Hello_212131.txt
//networkfolder/subfolder2/41241_Hello21312312.txt
//networkfolder/subfolder3/23_12122112Hello.txt

I want to be able to copy the files that have the string pattern "Hello".


Solution

  • Here is a possible solution:

    FOR /R \\networkfolder\ %%A IN (*Hello*) DO command
    

    Should work for you. You can search more about the for /R loop.