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