Automatically Delete Old Files - 03 Nov 2003


Share your scripting discoveries, comments, problems, solutions, and experiences with products. Email your contributions (500 words or less) to [email protected] We edit submissions for style, grammar, and length. If we print your submission, you'll get $100.

Automatically Delete Old Files
One of my responsibilities as a network engineer is to manage my company's FTP server. Although we repeatedly ask our users to clean out their directories and delete old files, our server is consistently overloaded. To solve this problem, I decided to write a script to automatically check the DateLastModified parameter and delete old files. Web Listing 1 (, InstantDoc ID 40511) contains my script, which I set Task Scheduler to run weekly. You'll need to modify the script's hard-coded path statements to match your environment.

The script contains a switch that when set to False checks the DateLastModified parameter and prints the results to a .csv file. This report contains the name of the file, date modified, size, and status. The report also tells the user how many files the script will delete and how much space will be freed. The first time I ran the script on my FTP server, I deleted 1165 files and regained 6.5GB of disk space.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.