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!

NextCard Internet Visa - Apply Now

 
  Categories:
Scripting
File Management via Windows Scripting
Figure 2: VBScript's File-Handling Objects

Continued from Figure 1.

To create a general-purpose file-deletion script, we use three of the four file-handling objects that come with the VBScripting engine. This table lists the properties and methods of these objects.

VBScript's File-Handling Objects
Properties and methods of FileSystemObjects
Drives property Returns a collection of Drive objects for all the drives in the file system.
BuildPath method Appends a filename to an existing path, inserting a separator if necessary.
CopyFile method Copies one or more files from one folder to another.
CopyFolder method Recursively copies a folder or subfolder to another.
CreateFolder method Creates a folder with a given name.
CreateTextFile method Creates a text file with the given file specification and returns a TextStream object that can be used to write to the file.
DeleteFile method Deletes the specified file.
DeleteFolder method Deletes the specified folder and all its contents--even if the folder has files in it.
DriveExists method Returns True only if the specified drive exists.
FileExists method Returns True only if the specified file exists.
FolderExists method Returns True only if the specified folder exists.
GetAbsolutePathName method Converts a relative path (such as "..\data") to a complete and unambiguous path specification.
GetBaseName method Returns the base filename of a path (minus any extension).
GetDrive method Returns a Drive object corresponding to a specified drive.
GetDriveName method Returns the drive portion of a path.
GetExtensionName method Returns the extension portion of a path.
GetFile method Returns a File object associated to the file specification.
GetFileName method Returns the filename portion (including extension) of a path.
GetFolder method Returns a Folder object for a given path specification.
GetParentFolderName method Returns a string that identifies the parent folder of a given folder.
GetSpecialFolder method Passes 0 to get the location of the Windows folder, 1 for the System folder, and 2 for the Temp folder.
GetTempName method Returns a randomly generated name for use as a temporary file or folder. (Although the documentation doesn't say so, experimentation seems to indicate that the name will be unique.)
MoveFile method Moves the file from one location to another.
MoveFolder method Moves the folder (including its contents) from one location to another.
OpenTextFile method Opens a file by returning a TextStream object you can use to write or append to the given object.
Properties and methods common to both Folder and File objects
Attributes property Sets or returns the attributes of the file or folder. (Uses bit masking to get at the individual attributes.)
DateCreated property Read-only property that returns the date and time the file or folder was created.
DateLastAccessed property Read-only property that returns the date and time the file or folder was last accessed.
DateLastModified property Read-only property that returns the date and time the file or folder was last modified.
Drive property Returns a Drive object for the drive on which the file or folder lives.
Name property Returns a string that gives the name of the file or folder.
ParentFolder property Returns a Folder object for the parent folder of the file or folder.
Path property Returns the path for the file or folder.
ShortName property Returns the name of the file or folder in 8+3 (DOS) format
ShortPath property Returns the pathname of the file or folder in 8+3 (DOS) format.
Size property Returns the size of the file in bytes, or the size of all files and subfolders in a folder.
Copy method Copies the folder (and all its contents) or the file from one location to another.
Delete method Deletes the file or folder even if it is not empty.
Move method Moves the folder (and all its contents) or the file from one location to another.
Properties and methods unique to Folder objects
IsRootFolder property Returns True if the folder is the root of the drive and False otherwise.
SubFolders property Returns a collection of the subfolders inside the given folder.
CreateTextFile method Creates a text file (or Unicode file) in the folder and returns a TextStream object to allow you to work with it.
Properties and methods unique to File objects
Type property Returns the file type registered with the system based on a file's extension.
OpenAsTextStream method Returns a TextStream object you can use to read from, write to, or append to the file.

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.