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 FileSystemObject Drive Drives File Files Folder Folders TextStream Main object Object Collection Object Collection Object Collection Object Description Allows creating, deleting, manipulating, and getting information about drives, folders, files Allows getting information about a drive Lists drives available on the system (both physical and logical) Allows creating, deleting, and moving files, as well as getting file properties Lists all files in a given folder Allows creating, moving, and deleting folders, as well as getting information about a particular folder Provides a list of all folders in a Folder Allows reading and writing text files

FileSystemObject object model Table B outlines the most often used methods of the FileSystemObject. Table B
Method CreateFolder CreateTextFile Description Creates a new folder Example fso.CreateFolder "C:\Files"

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 Deletes folder Deletes file fso.DeleteFolder "C:\Files" fso.DeleteFile "C:\Files.file.txt"

DeleteFolder DeleteFile CopyFolder

Copies a folder and its fso.CopyFolder "C:\Files", contents to another "C:\Files_Copy" folder Copies a file to another location Moves a folder to another location Moves a file to another location fso.CopyFile "C:\Files\file.txt", "C:\Files\file_copy.txt" fso.MoveFolder "C:\Files", "C:\Files Move" fso.MoveFile "C:\Files\file.txt", "C:\Files\file_move.txt"

CopyFile MoveFolder MoveFile 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

SystemFolder (contains available space. drive letter. libraries.txt") Then MsgBox "File Exists!" End if FolderExists FileExists • Common FileSystemObject methods . file system.Path) GetFolder GetParentFolderName Returns a string containing the name of the parent folder of the last component in a specified path GetSpecialFolder Returns the special folder specified. free space.GetSpecialFolder(TemporaryFolder) GetFile Returns a File object . drive type.FolderExists("C:\Files") Then MsgBox "Folder Exists!" End If If fso. or TemporaryFolder (used to store temp files) fso.FileExists("C:\Files\file.Path) fso.GetFile "C:\Files\file.txt" corresponding to the file in a specified path Checks whether a folder exists Checks whether a file exists If fso. One of three options: WindowsFolder (contains files installed by the Windows operating system).DriveExists("D") Then MsgBox "Drive D found" End If fso. total size DriveExists Checks whether a drive exists Returns a Folder object corresponding to the folder in a specified path If fso.GetParentFolderName(app. serial number.GetFolder(app. share name. device drivers).