• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 727
  • Last Modified:

Batch File

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
rrose987
Asked:
rrose987
1 Solution
 
EricIT ManagerCommented:
0
 
oBdACommented:
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
 
msiceCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now