Batch script to search certain folder names and copy a file there

Posted on 2011-10-18
Last Modified: 2012-05-12
I would like to build a batch script that searches out a certain folder name (e.g., "mainQC"), on all the hard drives of the computer and copy a file there.  So for instance, I have a file called "qa_fix.pk3", an the user has the folder name "mainQC" in a few different locations on their computer because each time they have installed the program folder to a different path.  

I need a batch that will search all the drives for all these folders and drop the file qa_fix.pk3 inside.  Also...
* the file to be copied would be in the same location as the script being executed.
* the copy commands would need to overwrite any existing file with such a name
* any and all error notifications should also be disabled

Please...try to answer the question.  I do not want to debate what I really think I need.  

Thanks in advance.  
Question by:icecom4
    LVL 5

    Accepted Solution

    This should do the job i think:

    @echo off

    IF EXIST dir_search.txt del /q /f dir_search.txt

    FOR %%i in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do @dir %%i:\*mainQC /s /b /ad>> dir_search.txt

    FOR /F "tokens=* delims=" %%x in (dir_search.txt) do @copy /v /y qa_fix.pk3 "%%x\qa_fix.pk3"

    del /q /f dir_search.txt
    LVL 67

    Expert Comment

    Be aware that the following code will not distinguish between local and network drives:
    @echo off
    set folder=mainQC
    set file=qa_fix.pk3
    for /F "tokens=1*" %%A in  ('fsutil fsinfo drives 2>nul') do set drives=%%B
    for %%D in (%drives%) do ^
    for /F "tokens=*" %%F in ('dir /s/b/a:d %%D%folder% 2>nul') do ^
    copy "%~dp0%file%" "%%F\" /y 2>nul

    Open in new window


    Author Closing Comment

    script worked exactly as expected

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Ok I have been working on this for some time having learned and gained certification in XenDesktop 4 along came version 5 which was released last month. Since then I have been working to deploy XenDesktop 5 in a small environment with only 2 virt…
    If your system is showing symptoms of browser hijacks or 'google search redirects' check out my other article ( first and run the tool TDSSKiller ( to get rid of the infection. Once done, and if the …
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now