Solved

delete files older than 30 days

Posted on 2009-06-30
8
506 Views
Last Modified: 2012-05-07
I would like to run a batch job to delete all files older than 30 days from the following directory:
D:\ImportData\Customer\Database\source\Archive
Creating a log of file names that have been deleted and storing the log
D:\ImportData\Customer\Database\source\Logs

Can someone please provide the appropriate script for Windows Server 2003?
0
Comment
Question by:ZSLLC
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 10

Expert Comment

by:Kieran_Burns
ID: 24745102
Robocopy is your friend for this (go download it)
syntax would be something like:
md d:\purgefolder
robocopy D:\ImportData\Customer\Database\source\Archive d:\purgefolder /s /mov /minage:30 /v >>D:\ImportData\Customer\Database\source\Logs\purgelog.txt

deltree d:\purgefolder

0
 

Author Comment

by:ZSLLC
ID: 24746020
Sorry but this does not address the entire question.
0
 
LVL 10

Expert Comment

by:Kieran_Burns
ID: 24746040
Which bit do you think is missing?
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 10

Accepted Solution

by:
Kieran_Burns earned 50 total points
ID: 24746157
Slight amendment

md d:\purgefolder
robocopy D:\ImportData\Customer\Database\source\Archive d:\purgefolder /s /mov /minage:30 /log:D:\ImportData\Customer\Database\source\Logs\logfile.txt

del d:\purgefolder /q/s
 
the /v was verbose output and thyis was echoed to the log file but the above is cleaner
the /s searches sub-folders (not bothered with /e as you dont need to move empty folders (unless you want to)
/move move the files out
/minage only moves files older than 30 days
I think that covers everything
 
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24749666
Okay, for 30 points I'm going to say 'Robocpoy'. No more!
0
 

Author Comment

by:ZSLLC
ID: 24749715
OK.  Obviously I don't know how to play the game.  Thanks for your help.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 24839644
t0t0,
*very fat grin*, I got YOU recommending RoboCopy?
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24839752
Yeah, I thought I never would but... well, it was a 'points'-thing... although, if i come across an interesting challenge I'd answer if for no points.

Oh, and thanks for mentioning me and the 'EndLocal & set...' thing in another thread..

Anyway, it was a nice little earner for Kieran_Burns.... and I think ZSLLC learned something too - and I'm not just refering to Robocopy...

Have a cracking day :)
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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