O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

File Object

Createable

No

Returned by

Files.Item property
FileSystemObject.GetFile method

Library

Microsoft Scripting Runtime

Description

The File object represents a disk file that can be a file of any type and allows you to interrogate the properties of the file and to move upward in the filesystem hierarchy to interrogate the system on which the file resides. The process of instantiating a File object—for example, assigning a reference from the File object’s Item property to a local object variable—doesn’t open the file. An open file is represented in the File System object model by a TextStream object, which can be generated by the File object’s OpenAsTextStream method.

There are several methods of retrieving a reference to an existing File object:

  • If you want to work with a particular file, you can retrieve a reference to it directly by calling the GetFile method of the FileSystemObject object. For example:

    Dim oFS, oFile 
    Set oFS = CreateObject("Scripting.FileSystemObject")
    Set oFile = oFS.GetFile("C:\Documents\MyReport.doc")

    allows you to retrieve a reference to a File object representing the MyReport.doc file without having to use the File System object model to navigate the filesystem.

  • If you want to work with a file as a member of a folder or of a set of files, you can retrieve a reference to a File object that represents it from the Item property of the Files collection. (The Files collection is returned by the Files property of a Folder object.) The following code fragment, for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required