GetFile Method

Returns a reference to File object corresponding to the file in a specified path.

Syntax

object.GetFile(filespec)

Arguments:

  • Object: Required. Always the name of a FileSystemObject.
  • Filespec: Required. The filespec is the absolute path to a specific file.

Remarks

An error occurs if the specified file does not exist. The GetFile method does not support the use of wildcard characters, such as ? or *.

The following example illustrates the use of the GetFile method.

Example 1:

Function GetFileSize(filespec)
    Dim fso, f, s
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFile(filespec)
    s = "File size: " & f.Size & " bytes"
    GetFileSize = s
End Function

'Usage
Dim fileSize
fileSize = GetFileSize("C:\Temp\test.txt")

Note:

The file mentioned in filespec should be present, otherwise an error will occur