|
You used to use batch files to automate system chores. Now there's a new way to get things done. By Gary Cornell Consider the following common task: You want to delete all the stray temporary (TMP) files on your C: drive. If you're running Windows 95 or NT, you'd probably do it like this: Use the Find option in Windows Explorer to get a list of all the TMP files, making sure to check off the Include subfolders option. Press Ctrl-A to select all the files that were found. Press Delete. This isn't hard, but you may hit a snag: The operation halts if Windows encounters a TMP file it can't delete (access is denied if the file is in use). If you're used to batch files, you may have tried a different technique: First you create a file containing the names of all the TMP files by entering DIR C:\*.TMP /A/B/S > deltmp.bat on the command line. Then, you edit the resulting batch file to put DEL at the start of each line and, finally, run the batch file--a fairly cumbersome solution for a relatively simple task! The upshot is that there is no really convenient way to delete all those TMP files. Enter the Windows Scripting Host, Microsoft's recently released language-independent scripting host for 32-bit Windows. As we'll see, using the WSH's powerful file- and folder-handling facilities, it is a relatively easy job to write a script that deletes all files with a specific extension. (If you're not yet familiar with the Windows Scripting Host, take a look at "The Windows Scripting Host" in our February 10, 1998, issue.) In this article we'll use VBScript, though the scripting engine supports JScript as well. (One advantage to using VBScript is that you can usually develop your script code in the free Visual Basic Control Creation Edition, which allows you to use all of VB's neat interactive debugging facilities.) Gary Cornell teaches at the University of Connecticut and has written or cowritten more than 20 computer books. His latest book, called Learn VBScript Now, was recently published by Microsoft Press. Next: File Management Objects Published as Operating Systems in the 6/30/98 issue of PC Magazine. |
|
TOP |
Copyright (c) 1998 Ziff-Davis Inc. |