Solved

Delete files older then "X" days old through a command line

Posted on 2006-10-19
3
11,403 Views
Last Modified: 2013-12-28
I'm looking for a program that will delete files in a specified folder older then, say a week old.  I need the program to be launched from a command prompt, and the output must be through the command prompt.  Reason being is i'm logging the deletion, and monitoring how much is building up.  I've found a program that works, but the output is not in the command window so i can't capture it into a text file.

Here's the software that works:
DELOLD - http://www.michna.com/software.htm

I'd prefer a free tool, or at least one with a free trial.

Thanks
0
Comment
Question by:cyrusuncc
3 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 17768462
A rather uncommon, but easy to realize possibility which would remove old files as well as giving you a detailed log how many files and which file size had been deleted would be through robocopy.
Use robocopy to move the files to a folder "Garbage" or whatever, then simply delete the "Garbage" folder. robocopy has extensive log functions, can append to or recreate the log file, can check for a minimum file age.

Windows Server 2003 Resource Kit Tools
http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

So all you'd need is a little script, for example like this:

@echo off
robocopy "C:\Old Files\" "C:\Garbage\" *.* /s /mov /create /minage:7 /log:"C:\Log Files\DelOld.log"
rd C:\Garbage /s /q

"/s" processes subdirectories (if necessary), "/mov" will move the files after the copy, and to speed things up as well as save space, you can use the "/create" switch; this will not copy the file's content, but just create the folders and files with a size of zero bytes. /minage:7 will only copy files that are at least 7 days old. "/log" will log what happened (/log+... would append to an existing log file).
Other switches (how much to log, for example) are described by robocopy /? and in robocopy.doc in the installation folder.
0
 
LVL 2

Author Comment

by:cyrusuncc
ID: 17769566
Thanks, i'm going to take a look at this.  I think it will work for my purposes!
0
 

Expert Comment

by:swintec
ID: 22304323
great share! I was looking for such a tool!

thx
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

679 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