Solved

delete files older than 30 days

Posted on 2009-06-30
8
505 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

860 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