Skip to content

Delete Temporary Files

Doug Lockwood edited this page Jun 22, 2017 · 1 revision

DeleteTemporaryFiles

DeleteTemporaryFiles

This Windows application can be run as a scheduled task to move files from a designated temporary location to the Recycle Bin if those files are older than the specified number of days.

Purpose

Years ago, when browsing the web, if you came across a downloadable file on the internet, and you happened to be using Internet Explorer, when you clicked on the download link, you'd see a message something like this:

If you clicked on the "Open" link, the file would (of course) still be downloaded to your computer. But it was downloaded to a temporary Windows-managed folder "somewhere" on your system. Over time, the system would purge the contents of this temporary folder automagically, thus cleaning up all of your downloaded junk over time.

For some reason, Internet Explorer stopped offering this functionality, and now files are typically downloaded to a non-managed folder. This folder, over time, needs to be cleaned out of all of the clutter that builds up. As a developer, especially, I find that I am always downloading files from the Internet to test out on my computer. Most of them I don't need to keep for more than a few minutes, or a few days at the most.

I, for one, don't have enough free time in my life to spend it cleaning out my downloads folder on my computer. So I built this program so that I could designate a folder on my system for temporary files, and run a scheduled task that would automatically clean up this folder in the background without any input from me.

About the Application

The first draft of this application was written in VB Script. I don't remember exactly when I first wrote it, but it was probably around 2007 or 2008. In the original version, I hard-coded the location of the temporary folder in the script itself, so I couldn't run the script on multiple computers without modifying it. A few years ago, I re-wrote it to accept command-line parameters that could be used to pass in the temporary folder location, which made it far easier to run the application on multiple machines. It also made it a possible to run the application multiple times in a single scheduled task, each time passing in a new folder location parameter.

In 2017, I finally ported the application to an ASP.NET C# Windows Application that can be run as a scheduled task. There is no GUI included with the application...it simply runs in the background without any user interaction.

Although I am still actively developing this project to add improvements to the application, it is currently fully-functional and I have been using it myself on my personal and professional computers without any problems.

Instructions

  1. Download the executable file (Available here) and save it somewhere you'll be able to access later on.

  2. Create a new scheduled task using the Windows Task Scheduler. In the "Program/Script" prompt, enter (or select) the path to the DeleteTemporaryFiles.exe file. In the "Add Arguments (optional)" field, enter the file path to the temporary folder you want to scan, surrounded by quotes, followed by a space and then a number indicating the number of days you want your temporary files to be available.

Notes

  • If the folder specified in the command line arguments does not exist, the application will create it automatically
  • It is very important you surround the folder path argument with quotation marks, otherwise the program may scan the wrong folder and delete potentially irreplaceable files!
  • Every time the program runs, it will create a log file identifying the actions taken
  • If something goes wrong, the application will create a log in your %AppData% folder under "DeleteTemporaryFiles"

WARNING! Use at your own risk!

This application comes with no warranty whatsoever. I don't actually recommend you download and run it without viewing the source code and fully understanding what it is doing. THIS APPLICATION DELETES FILES FROM YOUR COMPUTER! If you enter the wrong parameters, you can seriously damage your system, potentially making it inoperable. I am not aware of any bugs in the application, but if there are any (now or in future releases), the application can potentially have disastrous effects on your system. USE WITH EXTREME CAUTION!

Download

WARNING: Download this file at your own risk! Please see the warnings in the ReadMe file!

Clone this wiki locally