Page 1 of 1

find specific files in a folder and all its subfolders

Posted: 22 Jan 2012 01:26
by ladduq
Hi all,

Good day :)

I'm new to batch programming. :|

I need a batch script that will search for a specific list of file names
in a folder and all its sub folders and if found then copy it to some
other folder

For Example: I have root directory in that i have lots of sub folders
which contain lots of files.However i do not need all files so i need to
search for a specific files named like

"login.java"
"register.js"
"list.xls"
"authenticate.bteq"

remember the extensions for files are different.so i need a
batch script which can automatically do the work.

The file names can be inputted from a textfile and then search
in a folder and all its subfolders,if found the file then copy it to
some new folder.

any alternative suggestion is also appreciated.

please help... :)

Re: find specific files in a folder and all its subfolders

Posted: 22 Jan 2012 09:09
by aGerman
Try something like that:

Code: Select all

md "C:\whereever\newfolder"
pushd "C:\whereever\root"
for /f "delims=" %%i in (
  'dir /a-d /b /s "login.java" "register.js" "list.xls" "authenticate.bteq"'
) do (
  copy "%%i" "C:\whereever\newfolder\"
)
popd

Regards
aGerman

Re: find specific files in a folder and all its subfolders

Posted: 22 Jan 2012 11:19
by dbenham
@ladduq

What do you think will happen if a file like "login.java" appears in multiple source folders :?:
Obviously you can't have 2 files with the same name in the one destination folder. You should think about how you want to handle duplicate file names.

Dave Benham

Re: find specific files in a folder and all its subfolders

Posted: 20 Feb 2012 06:23
by ladduq
@dbenham

Thats a good point to note.

However there will be only a limited multiple instances say 2-3 files
and the others have only a single instance.

I checked the script written above it overwrites if there
are multiple instances.Focus is on moving the specific files
automatically from one folder to another.It works good.

Anyways Thank you for giving me a valid point which surely
should be considered.

:)

Re: find specific files in a folder and all its subfolders

Posted: 20 Feb 2012 06:25
by ladduq
@aGerman

Thank you for your reply.

I have checked with it and it works fine.

Superb

:) :) :)