Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete old files with a batch script 2

Status
Not open for further replies.

holdahl

IS-IT--Management
Apr 4, 2006
213
NO
Hi

Could anyone help with this one...
I want to create a batch script which goes into a directory and checks if any files in that directory are older than yesterdays date. If any files are, then delete them.

Is this easy to do with a bacth script?


sH
 
Nice one monsterjta. *





When you are the IT director, it's your job to make sure the IT works. If it does work they know already and if it doesn't, they don't want to hear your pathetic excuses.
 
hmm...

got this to work:
del_files.bat
----------------------------------------------------------
forfiles /p d:\FTPData /s /m *.* /d -10 /c "cmd /c del @file : date >= 10 days"
----------------------------------------------------------

it works fine, but what if I want to run this at weekends?
how can I check what day of the week it is?

sH
 
Like previously mentioned, setup a scheduled task.

Hope This Helps,

Good Luck!
 
is it not possible to have a script which should work for 2 different conditions?
like;
-----------------------------------------------------------
@ECHO OFF
IF "%DAY%" == "Monday" GOTO FIRST

:SECOND
forfiles /p d:\FTPData /s /m *.* /d -5 /c "cmd /c del @file : date >= 4 days > NUL"

:FIRST
forfiles /p d:\FTPData /s /m *.* /d -3 /c "cmd /c del @file : date >= 2 days > NUL"
----------------------------------------------------------
a bit strange happens because it jumps to :FIRST even though it's not monday

sH
 
hmmm.. a bit tired this morning.
well, works now

---------------------------------------------------------
@ECHO OFF
IF "%DAY%" == "Monday" GOTO FIRST

:SECOND
forfiles /p d:\FTPData /s /m *.* /d -2 /c "cmd /c del @file : date >= 1 day > NUL"
GOTO END

:FIRST
forfiles /p d:\FTPData /s /m *.* /d -4 /c "cmd /c del @file : date >= 3 days > NUL"
GOTO END

:END
--------------------------------------------------------

thanks for all suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top