Solved

Batch File

Posted on 2004-08-04
3
701 Views
Last Modified: 2010-04-14
Can anyone help me out with writing a batch file that will delete any .zip files in a specific directory that are older than 2 months?
0
Comment
Question by:rrose987
3 Comments
 
LVL 11

Expert Comment

by:Eric
ID: 11719940
0
 
LVL 83

Accepted Solution

by:
oBdA earned 125 total points
ID: 11720645
One of the easier ways is to use one of the best copy tools ever, robocopy, for this. robocopy is part of the W2k Resource Kit, and it's part of the downloadable W2k3 Resource Kit as well (the W2k3 RK needs to be installed on an XP or W2k3 machine, but robocopy.exe can then be copied to where you need it). This will save the necessity to calculate the date, which is a messy business, especially with localized versions.
Windows Server 2003 Resource Kit Tools
http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

This script uses robocopy to move files older than the specified days to a separate folder, then simply delete the files in the other folder.

====8<----[DelOld.cmd]----
@echo off
setlocal
set RootDir=D:\Test
set TempDir=D:\DeleteMe
set FileMask=*.zip
set Days=60

robocopy "%RootDir%" "%TempDir%" "%FileMask%" /minage:%Days% /mov /is /r:3 /w:5
del "%TempDir%\%FileMask%"
====8<----[DelOld.cmd]----
0
 
LVL 7

Expert Comment

by:msice
ID: 11720677
I use Perl for this - check this code out works great http://www.winnetmag.com/Article/ArticleID/27332/27332.html you need to have perl installed though - its free and found here http://www.activestate.com/Products/ActivePerl/ 
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now