find specific files in a folder and all its subfolders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ladduq
Posts: 31
Joined: 22 Jan 2012 01:08

find specific files in a folder and all its subfolders

#1 Post by ladduq » 22 Jan 2012 01:26

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... :)

aGerman
Expert
Posts: 4740
Joined: 22 Jan 2010 18:01
Location: Germany

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

#2 Post by aGerman » 22 Jan 2012 09:09

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

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

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

#3 Post by dbenham » 22 Jan 2012 11:19

@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

ladduq
Posts: 31
Joined: 22 Jan 2012 01:08

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

#4 Post by ladduq » 20 Feb 2012 06:23

@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.

:)

ladduq
Posts: 31
Joined: 22 Jan 2012 01:08

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

#5 Post by ladduq » 20 Feb 2012 06:25

@aGerman

Thank you for your reply.

I have checked with it and it works fine.

Superb

:) :) :)

Post Reply