Link to home
Start Free TrialLog in
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
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

This may not be of much help, but try having a look at robocopy dos command.
Avatar of M. Saad
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
> 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 "?
Avatar of 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
Try...
ROBOCOPY "\\server\sharename\engineering\client\IK" "c:\destinationfolder" *50160-340-P-1125* /E /DCOPY:T

Open in new window

Avatar of 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 ?
> ...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

> 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.
Avatar of 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
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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
> 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.