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
M. SaadAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nitin SontakkeDeveloperCommented:
This may not be of much help, but try having a look at robocopy dos command.
0
M. SaadAuthor Commented:
Thanks Nitin for your reply, but i really dont know it , i wish if i can have script or VBA code easier
0
NVITCommented:
> 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 "?
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

M. SaadAuthor Commented:
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
0
NVITCommented:
Try...
ROBOCOPY "\\server\sharename\engineering\client\IK" "c:\destinationfolder" *50160-340-P-1125* /E /DCOPY:T

Open in new window

0
M. SaadAuthor Commented:
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 ?
0
NVITCommented:
> ...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

0
NVITCommented:
> 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.
0
M. SaadAuthor Commented:
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
0
NVITCommented:
Thanks for that clarification.

Here is a tested and enhanced version of my prior code post.
Before using, please revise the values of these variables to your need: SrcDir, TgtDir, FileList

@echo off

set SrcDir=\\server\sharename\engineering\client\IK
set TgtDir=c:\destinationfolder
set FileList=c:\sample.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"
)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
M. SaadAuthor Commented:
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
0
NVITCommented:
> 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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.