Get 3.9% APR, Get Instant Credit - Click here!

PC Magazine

  PC Tech

File Management via Windows Scripting

Introduction

File Management Objects

A General-Purpose File-Deletion Script

A Few Details

Figure 1: File deletion script

Figure 2: VBScript's File-Handling Objects



X10.com - The SuperSite for Home Automation!

FREE investing information on 400 top companies - click here!

 
  Categories
Scripting Languages
Windows 95/NT
Operating Systems
Related Stories:
The Windows Scripting Host
-- Operating Systems 2/10/98

File Management via Windows Scripting
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.


 SPONSORED LINKS
@Backup   Your Solid Online Backup Plan. Download Now.
Services   9c/MINUTE LONG DISTANCE, 5c/MINUTE ON SUNDAYS!
STORAGE   Quantum means non-stop business, 24 hours a day
Software   X10.com -- The SuperSite for Home Automation
Books   Bargain Books up to 90% off at barnesandnoble.com
 ZDNET FEATURED LINKS
Downloads   Check out the best new downloads in Reviewer's Raves
Bargains!   Shop the Basement for best buys on computer products
Free Help   Got computing questions? ZDHelp has all the answers!
 MAGAZINE OFFERS
Free Offer   Get a FREE SUBSCRIPTION to Inter@ctive Week

TOP
Copyright (c) 1998 Ziff-Davis Inc.