Downloads
37718.zip

\[Editor's Note: Share your scripting discoveries, comments, problems, solutions, and experiences with products. Email your contributions (500 words or less) to r2rwinscriptsol@winnetmag.com. We edit submissions for style, grammar, and length. If we print your submission, you'll get $100.\]

My company uses an application that generates a log file every day. Thus, I needed to write a script that would delete log files older than 30 days. I wrote the simple Windows NT shell script that Listing 1 shows. You can configure a scheduler program to run the script as often as you want.

The script has two main lines: The first gathers the files' names into a text file, and the second deletes the files. The text file lists the files according to their creation dates. When the script parses the file, the script uses the For command's skip option to skip over the first 29 entries in the list and delete the remaining entries.

In the script, E:\testing\ is a variable. You need to specify the path or file type if you're running the script in a different folder or drive. You can replace the Do Del command with any other command you want the script to execute. If you use the Copy or Move commands, you need to include the destination path at the end of the line. Listing 2 gives you the alternative of not creating a temp file.