Computing.Net > Forums > Programming > Search with batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Search with batch file

Reply to Message Icon

Name: amlife
Date: October 27, 2008 at 06:13:21 Pacific
OS: XP
CPU/Ram: 2GB
Product: HP
Comment:

Hello

I was wondering it it is possible to creat
batch file will search %systemdrive% for
files and backup them up to backup folder.

example.

search for *.jpg and copy to backup\jpg
search for *.doc and copy to backup\MS word
search for *.ppt and copy to backup\MS power
point


I tired to use IF FOUND statement. but it will look into single directory not sure if there is any special switch will make it look into subdirectories

Thank you



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: October 27, 2008 at 07:10:47 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for %%a in (jpg doc ppt) do (
for /f "tokens=* delims= " %%f in ('dir/b/s/a-d %systemdrive%\*.%%a') do (
echo copy "%%f" d:\bakup\%%a
)
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: amlife
Date: October 27, 2008 at 07:21:35 Pacific
Reply:

Thanks Mechanix2Go

I just want to know now, will this search the
entire hard drive ? including all subfolders?

how can I add more extensions ex. *.GIF *.XLS

Thank you


0

Response Number 3
Name: Mechanix2Go
Date: October 27, 2008 at 07:27:12 Pacific
Reply:

Yes, it'll do the whole drive.

Put additional exts in here:

(jpg doc ppt)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: amlife
Date: October 27, 2008 at 07:33:39 Pacific
Reply:

sounds good, thanks for your help, will create that bat file and will post feedback soon :-)


0

Response Number 5
Name: amlife
Date: October 27, 2008 at 08:27:28 Pacific
Reply:

ok .. I'm not sure what is wrong, but it not copying anything .. I can't see anything in the "bakup" folder. however I was able to see listing for all extensions provided, I didn't see any errors..


0


Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: October 27, 2008 at 08:33:18 Pacific
Reply:

Sorry as written, it previews what's to be done.

To activate, edit out the ECHO before COPY.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: amlife
Date: October 27, 2008 at 09:39:28 Pacific
Reply:

removed the echo, and it is working as it
should be .. thanks again for your assistance.


0

Sponsored Link
Ads by Google
Reply to Message Icon

About C# programming compile file java with vb...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Search with batch file

Get last line with batch file www.computing.net/answers/programming/get-last-line-with-batch-file/17019.html

Deleting lines with batch files www.computing.net/answers/programming/deleting-lines-with-batch-files/13330.html

editing text file with batch file www.computing.net/answers/programming/editing-text-file-with-batch-file/15231.html