multiple file type search

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
programchen
Posts: 10
Joined: 21 Nov 2011 23:43

multiple file type search

#1 Post by programchen » 26 Nov 2011 01:28

is there any command to search all the *.doc, *.pdf, *.xls created after 2010.Jan.1 inside the C drive (including sub-directory)

then copy above files to D drive? thanks

paultomasi
Posts: 25
Joined: 24 Feb 2009 14:52
Location: UK
Contact:

Re: multiple file type search

#2 Post by paultomasi » 26 Nov 2011 17:18

Try this simple batch file. change the second line to point to your own destination folder on drive D:.

Code: Select all

@echo off
set destination=d:\temp

md %destination% 2>nul

for %%a in (doc pdf xls) do (
  xcopy "*.%%a" "%destination%" /c /d:11-1-2011 /s
)

programchen
Posts: 10
Joined: 21 Nov 2011 23:43

Re: multiple file type search

#3 Post by programchen » 26 Nov 2011 21:28

I already has directory temp, no need to md.

should I use:
@echo off
for %%a in (doc pdf xls) do (
xcopy "*.%%a" "%destination%" /c /d:11-1-2011 /s
)

how to exclude doc and xls inside windows directory, I don't know the exact location of windows installation path.

paultomasi
Posts: 25
Joined: 24 Feb 2009 14:52
Location: UK
Contact:

Re: multiple file type search

#4 Post by paultomasi » 27 Nov 2011 02:59

Don't for get to set your destination path after the '=' on the 2nd line or hardcode it into the xcopy command.

Code: Select all

@echo off
set destination=
echo %windir%>exclude.tmp
for %%a in (doc pdf xls) do (
  xcopy "*.%%a" "%destination%" /c /d:11-1-2011 /s /exclude:exclude.tmp
)
del exclude.tmp

programchen
Posts: 10
Joined: 21 Nov 2011 23:43

Re: multiple file type search

#5 Post by programchen » 30 Dec 2011 02:15

I save this batch file in c:\, after that I run the batch, it says can't perform a cycle copy, 0 files copied

if I put this batch file in c:\abc, only abc folder document file are copied.

how to solve the problem?

@echo off
set destination=c:\ttmp
echo %windir%>exclude.tmp
for %%a in (doc pdf xls ppt) do (
xcopy "*.%%a" "%destination%" /c /s /exclude:exclude.tmp
)
del exclude.tmp

programchen
Posts: 10
Joined: 21 Nov 2011 23:43

Re: multiple file type search

#6 Post by programchen » 30 Dec 2011 02:25

my requirement is copy files from the whole c drive including subdirectory, not copy files from current directory

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

Re: multiple file type search

#7 Post by aGerman » 30 Dec 2011 08:04

There are several possibilities.

Code: Select all

for /r "C:\" %%i in (*.doc *.pdf *.xls *.ppt) do ... [whatever you want to do with the files]

Regards
aGerman

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: multiple file type search

#8 Post by Squashman » 30 Dec 2011 08:50

programchen wrote:I save this batch file in c:\, after that I run the batch, it says can't perform a cycle copy, 0 files copied

Of course that is going to happen if you execute it from the root of the drive. You said earlier that you wanted to copy to the D: drive though. If you were copying to a separate drive then you would not get the cyclical copy error. You can't say you want to copy from the root of the whole drive and then copy to a folder on that same drive. That is a cyclical copy.

programchen
Posts: 10
Joined: 21 Nov 2011 23:43

Re: multiple file type search

#9 Post by programchen » 31 Dec 2011 02:25

thanks, I want to copy those files to d drive, after copy, delete those files in c drive (including subdirectory)

how to resolve?

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

Re: multiple file type search

#10 Post by aGerman » 31 Dec 2011 07:46

programchen wrote:after copy, delete those files in c drive

robocopy /? Have a look at the /mov option.

programchen wrote:(including subdirectory)

Are you sure?
Imagine there is a .doc file in c:\whereever\sub1 and another .doc file in c:\whereever\sub1\sub2. What happen if the first .doc is copied and sub1 is removed? ... Also what about other file types in these directories?

Regards
aGerman

Post Reply