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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete files older that 24 with a batch file 2

Status
Not open for further replies.

paulovey

Technical User
Jul 13, 2000
458
0
0
GB
Hi,

Im not sure if this the right place to ask this, but I do know the knowledge here covers a lot more than just win2k.

I have a situation where customers can upload their data to our ftp server so we can fix it, and we really need to clear off all data older than 24 hours every day.

Is there a way that I can achieve this in a batch file.

I cant just schedule a job that runs at say 2am each morning, as there may still be an active file transfer, I just need to identify and delete files older than 24hours.

Thanks,

Paul

If aint broken, dont try n fix it!!!!!
 
You should take a look at the forfiles.exe utility in the
Win2K resource kit. I use it in a batch file to delete files old files on my FTP server:

rem Delete FTP data files on the server for more than 14 days.
forfiles -pe:\ftpdata -s -d-14 -c"cmd /c del ""@FILE"" /Q /F"

rem Delete log files older than 90 days
forfiles -pe:\iftplog -s -d-90 -c"cmd /c del ""@FILE"" /Q /F"

Good luck.
 
Addendum to my previous post:

I run this batch file daily in a scheduled task.
 
Fantastic Andy thanks for that! That earns you a little star! :)

If aint broken, dont try n fix it!!!!!
 
can someone please tell me where i can find the forfile utility? i need it very much..
i have a Resource kit cd here but it isnt on the cd :s also microsoft.com doesnt tell anything about forfile.exe
 
thnx !
i really couldnt find anything about it.
and yeah maybe i searched for ForFile and not for ForFileS
 
hello people
ive got the forfiles.exe now..
and i see andy uses this code to delete files:

forfiles -pe:\ftpdata -s -d-14 -c"cmd /c del ""@FILE"" /Q /F"

but i want the files to be copied to another folder.
how can i do that?
ive tried it many times. changed 'del' in 'copy' offcourse, but what next?

forfiles -pe:\test -s -d-1 -c"cmd /c copy ""@FILE"" /Q /F f:\test2

for example above i wanted all files older then 1 day to be copied to the folder 'test2'.
didnt work.
anyone?


 
You want to look at a different util in the resource kit called robocopy. Syntax on 2k would be the following:

robocopy c:\source z:\destination /mir /sec /purge /minage:14 /r:5 /w:15 /np

And the xp/2k3 version of the util really has some power.
 
Do a search for +DOS +"delete by date" on the web.
There a various DOS commands you can use. I believe I use pdelete.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top