Class File (Scripting VBA)

Provides access to all the properties of a file.

Class FileSystemObject gives access to class File.

Methods

Copy - Copies a specified file or folder from one location to another.

Delete - Deletes a specified file or folder.

OpenAsTextStream - Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file.


Sub TextStreamTest
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
    Dim fs, f, ts, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    fs.CreateTextFile "test1.txt"            'Create a file
    Set f = fs.GetFile("test1.txt")
    Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
    ts.Write "Hello World"
    ts.Close
    Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
    s = ts.ReadLine
    MsgBox s
    ts.Close
End Sub

Move - Moves a specified file or folder from one location to another.

Properties

Path (Default member) - Returns the path for a specified file, folder, or drive.

Attributes sets or returns the attributes of files or folders. Read/write or read-only, depending on the attribute.

DateCreated returns the date and time that the specified file or folder was created.

DateLastAccessed returns the date and time that the specified file or folder was last accessed.

DateLastModified returns the date and time that the specified file or folder was last modified.

Drive returns the drive letter of the drive on which the specified file or folder resides.

Name sets or returns the name of a specified file or folder.

ParentFolder returns the folder object for the parent of the specified file or folder.

ShortName returns the short name used by programs that require the earlier 8.3 naming convention.

ShortPath returns the short path used by programs that require the earlier 8.3 file naming convention.

Size for files, returns the size, in bytes, of the specified file. For folders, returns the size, in bytes, of all files and subfolders contained in the folder.

Type returns information about the type of a file or folder. For example, for files ending in .TXT, "Text Document" is returned.

Drive - Provides access to the properties of a particular disk drive or network share.

Folder - Provides access to all the properties of a folder.

TextStream - Facilitates sequential access to file.