You are on page 1of 2

ou can then use its properties and methods, which are shown in Table A.

Table A
Object/collection Type Description
FileSystemObject Main object Allows creating, deleting, manipulating, and getting
information about drives, folders, files
Drive Object Allows getting information about a drive
Drives Collection Lists drives available on the system (both physical and
logical)
File Object Allows creating, deleting, and moving files, as well as
getting file properties
Files Collection Lists all files in a given folder
Folder Object Allows creating, moving, and deleting folders, as well
as getting information about a particular folder
Folders Collection Provides a list of all folders in a Folder
TextStream Object Allows reading and writing text files
FileSystemObject object model

Table B outlines the most often used methods of the FileSystemObject.


Table B
Method Description Example
CreateFolder Creates a new folder fso.CreateFolder "C:\Files"
CreateTextFile Creates a specified fso.CreateTextFile "C:\Files\file1.txt"
filename and returns a
TextStream object
that can be used to
read from or write to
the file
DeleteFolder Deletes folder fso.DeleteFolder "C:\Files"
DeleteFile Deletes file fso.DeleteFile "C:\Files.file.txt"
CopyFolder Copies a folder and its fso.CopyFolder "C:\Files",
contents to another "C:\Files_Copy"
folder
CopyFile Copies a file to fso.CopyFile "C:\Files\file.txt",
another location "C:\Files\file_copy.txt"
MoveFolder Moves a folder to fso.MoveFolder "C:\Files", "C:\Files
another location Move"
MoveFile Moves a file to fso.MoveFile "C:\Files\file.txt",
another location "C:\Files\file_move.txt"
GetDrive Returns a Drive object fso.GetDrive("C") AvailableSpace
corresponding to the
drive in a specified
path. Allows getting
various information
about the drive, such
as available space,
drive letter, drive type,
file system, free
space, serial number,
share name, total size
DriveExists Checks whether a If fso.DriveExists("D") Then
drive exists MsgBox "Drive D found"
End If
GetFolder Returns a Folder fso.GetFolder(app.Path)
object corresponding
to the folder in a
specified path
GetParentFolderName Returns a string fso.GetParentFolderName(app.Path)
containing the name
of the parent folder of
the last component in
a specified path
GetSpecialFolder Returns the special fso.GetSpecialFolder(TemporaryFolder)
folder specified. One
of three options:
WindowsFolder
(contains files
installed by the
Windows operating
system),
SystemFolder
(contains fonts,
libraries, device
drivers), or
TemporaryFolder
(used to store temp
files)
GetFile Returns a File object .GetFile "C:\Files\file.txt"
corresponding to the
file in a specified path
FolderExists Checks whether a If fso.FolderExists("C:\Files") Then
folder exists MsgBox "Folder Exists!"
End If
FileExists Checks whether a file If fso.FileExists("C:\Files\file.txt") Then
exists MsgBox "File Exists!"
End if

• Common FileSystemObject methods

You might also like