The File Object

The FSO model represents each file on a disk by a File object. The File object has methods and properties that permit you to get information about the file and to manipulate it. By manipulate, I mean actions such as moving and copying the file, not reading or writing its data (which were covered earlier in the chapter). Before you can do anything with a file, however, you must get a reference to the corresponding File object. There are two ways to do this.

If you know the path and the name of the file, you can use the GetFile method to return a File object that is associated with that file. Assuming that fso is a reference to the FileSystemObject, the syntax is

Dim f As Scripting.File
Set f = fso.GetFile(filename)

filename

Get Office® XP Development with VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.