\[Editor's Note: Email your scripting solutions (400 words or less) to Reader to Reader at [email protected]. Please include your script and phone number. We edit submissions for style, grammar, and length. If we print your contribution, you receive $100.\]
If you haven't installed a quota tool to make sure that users don't keep excessively large files (e.g., 50MB) on your Windows 2000 or Windows NT servers, you might find the script FindLargeFiles.vbs helpful. FindLargeFiles.vbs searches a specified folder and its subdirectories for files that exceed a specified size. You specify the folder to search and the size threshold when you launch the script at the command line. You use the syntax
FindLargeFiles.vbs Folder Max_Size_in_MB
where Folder is the folder's pathname and Max_Size_in_MB is the size threshold in megabytes. If a file exceeds the specified threshold, the script outputs the file's pathname and size to the screen and a log.
If the script finds at least one file over the size threshold, it sets the ERRORLEVEL environment variable to 1. That way, you have the option of inserting FindLargeFiles.vbs into an NT shell script for automatic launching and further processing. For example, the script Notify.cmd in Listing 1 first launches FindLargeFiles.vbs. If FindLargeFiles.vbs finds a file on \\server1\share1 that exceeds 50MB, Notify.cmd uses the messenger service to send the message Large files found! Check FindLargeFiles.log to the systems administrator.
You can download FindLargeFiles.vbs from the Code Library on the Windows Scripting Solutions Web site (http://www.winscriptingsolutions.com). I wrote FindLargeFiles.vbs for NT 4.0 machines running Service Pack 6a (SP6a), SP6, or SP5, but it also works on Win2K machines. You must have Windows Script Host (WSH) 2.0 installed. I recommend that you run FindLargeFiles.vbs with cscript.exe, not wscript.exe. If you use wscript.exe, a separate message box opens for each file checked.