command line search

D

David

What is the command, to do the search of a directory for
files modified two week ago or older and then delete
them? I want to use this in a script.
 
W

winter

What is the command, to do the search of a directory for
files modified two week ago or older and then delete
them? I want to use this in a script.

i use hfind, from foundstone. allows you to search on diff time stamps
(without altering them).

winter
 
J

Jerold Schulman

What is the command, to do the search of a directory for
files modified two week ago or older and then delete
them? I want to use this in a script.


Using the scripts in tips 721, 4835, 7320, and 7321 in the 'Tips & Tricks' at
http://www.jsiinc.com

@echo on
:: define yy mm dd of today
call univdate
:: define AYMD
call jsidatem %yy% %mm% %dd% - 14
:: Change to your drive and folder
pushd Drive:\Folder
for /f "Skip=4 Tokens=1,2,3,5* Delims=/ " %%f in ('dir /a-d /o-d /tw') do (
if not {%%j}=={} if {%%h%%f%%g} LEQ {%AYMD%} del /q "%%j"
)
popd

NOTE: The above assumes your short date format is MM/DD/YYYY


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
H

Herb Martin

David said:
What is the command, to do the search of a directory for
files modified two week ago or older and then delete
them? I want to use this in a script.

Someone will surely post a reference -- I don't think there is such
a built-in command.

I use a (really old DOS) command "WhereIs" (wi.exe) that a friend and
I wrot and a newer version for Win32 that I wrote (am writing.)

Try searching download sites for WhereIs or similar....
[/QUOTE]
 
P

Paul R. Sadowski

David said:
What is the command, to do the search of a directory for
files modified two week ago or older and then delete
them? I want to use this in a script.

I use a Win32 clone of the UNIX find command for such stuff:

find c:\temp -mtime +14 -exec rm -f '{}';
or
find c:\temp -mtime +14 -exec cmd /c del '{}';
 
M

Matthias Tacke

Paul R. Sadowski said:
I use a Win32 clone of the UNIX find command for such stuff:

find c:\temp -mtime +14 -exec rm -f '{}';
or
find c:\temp -mtime +14 -exec cmd /c del '{}';

That is nothing I would recommend as long as the syntax of the MS-find
isn't replicated 100%. There are a lot of batches around relying on the
presence of the original-MS find.exe in %systemroot%\system32.
 
M

Mark V

In said:
What is the command, to do the search of a directory for
files modified two week ago or older and then delete
them? I want to use this in a script.

No single command I know of. You might look at using FORFILES.EXE
(Resource Kit) in batch.


FORFILES v 1.1 - (e-mail address removed) - 4/98

Syntax : FORFILES [-pPath] [-mSearch Mask] [-ccommand] [-d<+|->
<DDMMYYYY|DD>] [-s]

-pPath Path where to start searching
-mSearch Mask Search files according to <Search Mask>
-cCommand Command to execute on each file(s)
-d<+|-><DDMMYYYY|DD> Select files with date >= or <=DDMMYYYY (UTC)
or files having date >= or <= (current date -
DD days)
-s Recurse directories
-v Verbose mode

The following variables can be used in Command :
@FILE, @FNAME_WITHOUT_EXT, @EXT, @PATH, @RELPATH, @ISDIR, @FSIZE,
@FDATE,
@FTIME

To include special hexa characters in the command line : use 0xHH

Default : <Directory : .> <Search Mask : *.*> <Command : "CMD /C
Echo @FILE">
Examples :
FORFILES -pc:\ -s -m*.BAT -c"CMD /C Echo @FILE is a batch file"
FORFILES -pc:\ -s -m*.* -c"CMD /C if @ISDIR==TRUE echo @FILE is a
directory"
FORFILES -pc:\ -s -m*.* -d-100 -c"CMD /C Echo @FILE : date >= 100
days"
FORFILES -pc:\ -s -m*.* -d-01011993 -c"CMD /C Echo @FILE is quite
old!"
FORFILES -pc:\ -s -m*.* -c"CMD /c echo extension of @FILE is 0x22
@EXT0x22"
 
P

Paul R. Sadowski

Matthias Tacke said:
That is nothing I would recommend as long as the syntax of the MS-find
isn't replicated 100%. There are a lot of batches around relying on the
presence of the original-MS find.exe in %systemroot%\system32.

It's not a replacement. You address it with the full path, c:\bin\find, for
example, or rename it, ufind.exe, for example.
 
M

Matthias Tacke

Mark said:
No single command I know of. You might look at using FORFILES.EXE
(Resource Kit) in batch.
My newsreader is missing the original poster, so my answer goes here.
I remember two switches buried under the 160 total of www.xxcopy.com

/RS remove source and /DA or /DB Date after/before.

<quote>
File age parameters (/DA# /DB# /Do#) now accept a value in days, hours,
minutes, or even seconds. Now you can say,
XXCOPY C:\ D:\ /DA#30M /S //
files 30 minutes or younger
XXCOPY \my\*JPG /DB#12H /RS //
delete *.JPG, 12 hrs or older
</quote>

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top