Solved

Batch File

Posted on 2004-08-04
3
710 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Expert Comment

by:Eric
ID: 11719940
0
 
LVL 84

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

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…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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