• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

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

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.  
1 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
QlemoC++ DeveloperCommented:
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

icecom4Author Commented:
script worked exactly as expected

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now