Skip navigation

Automatically Delete Old Files - 24 Jan 2007

Downloads
94627.zip

In my organization, we gave users access to a network drive on the file and print server on which they could store and share documents across departments. Unfortunately, users created folders and files indiscriminately. Within a few months, these folders and files accounted for several gigabits of server space.

Moving extraneous files and folders is time consuming during a server migration. In addition, we wanted to free up some of the disk space to make it available to other users. Administrators often manually delete old files, which requires opening each subfolder and checking file dates.

I wrote the Delfile.vbs script, which Listing 1 shows, to delete files based on their last modified date. The command runs in the CScript command shell, and the command syntax is:

delfile.vbs <path> <date last modified> <cfm delete = true(0) or false(1)(default)>

If 14 days from today you want to preview files that haven’t been modified since today, type:

delfile.vbs D:\IT 14 1

Setting the last parameter to 1 (false) causes the script to simply display the results. Figure 1 shows example output. To delete the files, change the parameter to 0:

delfile.vbs D:\IT 14 0

Before you use the script to delete files from your network, copy the files from the network drive to the local hard drive and test the script.

Hide comments

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.
Publish