Batch to search for various files located on server from text file then copy to target folder RRS feed

  • General discussion

  • Hello , wish to have your help in the following :

    I have a text file containing various files names  (without paths only name without extension )  All the documents start at "main folder named “TN” , then are scattered in various subdirectories.


    then inside the text file contains only the name of file :









    Since I have many a lot of subdirectories under the parent folder “ TN” I need to search for the file name mentioned in the text file and copy it to destination folder.

    I wish to have something like

     source patch : \\sever\DCC\Incoming\TN

    destination folder : C \ user \ desktop \ dest

    text file location : C \ user \ desktop \ search \ file-list. text


    I have a lot of subfolders under folder named “TN” ( approximately 40,000 folder) and then each folder contain other subfolder.

    Hope my question is clear

    Thanks in advance for any help

    • Changed type Bill_Stewart Wednesday, September 13, 2017 9:59 PM
    • Moved by Bill_Stewart Wednesday, September 13, 2017 9:59 PM This is not "scripts on demand"
    Wednesday, August 9, 2017 5:12 AM

All replies

  • Please read this first:

    This forum is for scripting questions rather than script requests

    -- Bill Stewart [Bill_Stewart]

    Wednesday, August 9, 2017 1:24 PM
  • Have a look at https://superuser.com/questions/893511/copy-all-files-with-a-certain-name-using-powershell you could modify the answer 

    Wednesday, August 9, 2017 2:25 PM
  • thanks for your message , and i apologize for this
    i have found one batch from other site and its working good only when it search within small amount of files & folders.
    my problem that i have very larg data ( about 300,000 ) files & folders and it takes about 1 hour to search for 1 single file ,then if i am searching for 2 files , then it will take about 2 hours and so on .
    the batch is mentioned below and i wish any help to speed it up :

    @echo off

    set SrcDir=C:\Users\user\Desktop\All
    set TgtDir=C:\Users\user\Desktop\Search Master\Search Result
    set FileList=C:\Users\user\Desktop\Search Master\temp.txt

    REM Copy desired files
    for /f "tokens=*" %%a in ('type "%FileList%"') do (
      ROBOCOPY "%SrcDir%" "%TgtDir%" "*%%a*" /E /DCOPY:T

    REM Since robocopy copies empty folders, we need to remove those.
    for /f "tokens=*" %%a in ('dir /b /s /ad "%TgtDir%" ^| sort /r') do (
      rd /q "%%a"
    Wednesday, August 9, 2017 2:29 PM
  • hello and thanks for your reply.
    i dont know really about powershell, so i just copied the code from that page and save it as bat file , change the source and destniation path , but still couldnt get anything.
    any advise ?
    Wednesday, August 9, 2017 2:54 PM