Previous Section Table of Contents Next Section

The FileSystemObject Library

The FSO is actually an object library, which simply means that it's made up of bunches of other objects. These other objects represent things like files and folders on your computer. As with any other object-or library-you start working with the FSO in a script by declaring a variable and creating an instance of the object.


Dim oFSO

Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")

TIP

Where do I get these object names? Generally, from their documentation. In the case of the FSO, the MSDN Library contains complete documentation under its Platform SDK section. If you're using the Library, either from CD, DVD, or http://msdn.Microsoft.com/library, look under Platform SDK first. Then look under Tools and Scripting, expanding each section as you go. Alternatively, open the index and simply type FileSystemObject to jump straight to an overview.


One look at the FSO's documentation and you may wonder what you've gotten yourself into. The FSO contains an almost bewildering number of properties, objects, and methods for you to work with. Don't let this bounty of options overwhelm you! The FSO only has four basic objects that you'll work with.

  • A Drive object represents a drive on your system. Drives can include removable drives, fixed drives, mapped network drives, and so forth.

  • A Folder object represents a folder in the file system.

  • A File object represents-you guessed it-a file.

  • A TextStream object represents a stream of text, which is a fancy way of describing a text file. More precisely, a TextStream allows you to pull (or stream) text in and out of a file, providing a handy way to work with the contents of text files.

All of the FSO's other methods, properties, and objects are designed for working with these four basic objects. I'll cover each of these objects in their own section, along with their associated properties and methods.

TIP

One of the things you often have to worry about with objects is whether the objects will be available on every machine that you want to run your script on. With the FSO, that's not a problem: It's implemented in Scrrun.dll, the Scripting Runtime, which is present on all Windows 2000 and later computers, Windows Me, and generally on Windows 98. In fact, on Windows 2000 and later, the file is under Windows File Protection and cannot easily be removed.


    Previous Section Table of Contents Next Section