Avatar of M. Saad
M. Saad
 asked on

search & copy files from sub-folders based on list to other folder

hello , i wish to have your help to copy some files from Company SERVER to my computer
i have server contain many folders and inside each folder many sub-folders and inside its other sub-folders
example : Contractor is the main folder
CCC is subfoder
Letters is sub-folder
incoming is sub-folder
outgoing is sub-folder
i want code or batch  to read list of names of some files / folder listed in text file " without extension " which  exist in any of these sub-folders and copy the result to destination folder

i want to set up the source folder as main folder " Contractor"  which is available on server but the search must be in all sub-folders under the main folder

hope the questions is clear

any help would be appreciated
VBA

Avatar of undefined
Last Comment
NVIT

8/22/2022 - Mon
Nitin Sontakke

This may not be of much help, but try having a look at robocopy dos command.
M. Saad

ASKER
Thanks Nitin for your reply, but i really dont know it , i wish if i can have script or VBA code easier
NVIT

> i want code or batch  to read list of names of some files / folder listed in text file " without extension " which  exist in any of these sub-folders and copy the result to destination folder

Please clarify " without extension "?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
M. Saad

ASKER
Thanks for your concern , kindly see below example :

I have my folder structure as you can see in the sample picture “ pic1”

Folder named “TN” contain many folders and each one of this folder contain subfolders as you can see for named “X-MEL-AGI-001885 “ example “ pic2 “


Subfolder named “50160-340-P-1125” suffix with 0 and its attachments you can see in the pic 3 for example.

Subfolder named “50160-340-P-1125” suffix with 1 and its attachments you can see in the pic 4 for example.

I want to search for the file named “50160-340-P-1125” ( regardless the suffix )  and in this example all files with this name are available into main folders

 “X-MEL-AGI-001885 “ and also under folder name “X-MEL-AGI-002420” as u can see in pic 5 for example


I just need batch or anything else that can help me to perform this task.
I need to just type the name of file and then search inside this folders in its subfolder and then copy them to specific destination on my desktop.

I wish that I explained myself better and my request is clear now.

Thx in advance for your time
pic-1.jpg
pic-2.jpg
pic-3.jpg
pic-4.jpg
pic-5.jpg
NVIT

Try...
ROBOCOPY "\\server\sharename\engineering\client\IK" "c:\destinationfolder" *50160-340-P-1125* /E /DCOPY:T

Open in new window

M. Saad

ASKER
update :
i just made batch file for this command , and i have try it
it copy everything in the folder named " TN" not only the file which i need
can you please check that ?




sorry , i am using Company's PC , and i cant use it here.
can it be like batch ?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
NVIT

> ...it copy everything in the folder named " TN" not only the file which i need
It works fine here. Except it also copies the empty folders. Here is a version that removes the empty folders.
set SrcDir=\\server\sharename\engineering\client\IK
set TgtDir=c:\destinationfolder
set CopyPattern=*50160-340-P-1125*
ROBOCOPY "%SrcDir%" "%TgtDir%" "%CopyPattern%" /E /DCOPY:T
for /f "tokens=*" %%a in ('dir /b /s /ad "%TgtDir%" ^| sort /r') do (
  rd /q "%%a"
)

Open in new window

NVIT

> i want code or batch  to read list of names of some files / folder listed in text file " without extension " which  exist in any of these sub-folders and copy the result to destination folder

Please provide example text file.
M. Saad

ASKER
i have attached sample for requied documents which i need to search under folder named "TN".

please note that each single number of these number have many copies in different sub-folders under main folder named "TN".
for example documnet no "50160-340-P-1125 " is available in following format :

50160-340-P-1125_0_0010.pdf
50160-340-P-1125_0_0020.dox
50160-340-P-1125_1_0010_Marked.pdf
50160-340-P-1125_2_0020.pdf
50160-340-P-1125_2F1_0020.pdf
50160-340-P-1125_4_0010.pdf

so , if i just add the documnet number " 50160-340-P-1125 "  into text file , i wish to have copy of all the above documents from all sub-folder under main folder named "TN".

i will search for many different numbers into text file not only 1 document number everytime.

wish its cleare for you & thanks in advance
sample.txt
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
NVIT

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
M. Saad

ASKER
Hello , thanks  a lot for your message , I have tested the batch many times and its very fast &good I just have 2 small issue if you can fix for me :

This batch work very good with the documents available on my PC but sometimes create empty folder which is not related to my search criteria.

Also if I wanted to search for document available on my Company’s server its not working at all, I have changed the path for “SrcDir” as you mentioned in your batch start with “\\10.10 etc “ but without positive result.
Would you please check this for me.

Thanks again for your time & effort
NVIT

> I have tested the batch many times and its very fast
This being true, question should be closed and points awarded.

> I just have 2 small issue if you can fix for me :
This could be small or big. I can't tell without putting in more time. Please open another question.