Before you can access specific information on the file system, you must first create the FileSystemObject. In the following example, we will create and destroy a FileSystemObject. The FileSystemObject object’s, like other ASP objects, has its own properties and methods

Properties

Methods

Common Methods

BuildPath

BuildPath allows you to build a path string from a root path and a folder to navigate to. Neither of the two parameters are required to represent actual files on the file system in order to build the path string. You can use absolute or relative references when building the path string. This function could be used to create an “explorer” type interface.

CopyFile

The CopyFile method copies one or more files from one location to another. Syntax: FileSystemObject.CopyFile source,destination[,overwrite]

CopyFolder

The CopyFolder method copies one or more folders from one location to another. Syntax: FileSystemObject.CopyFolder source,destination[,overwrite]

CreateFolder

The CreateFolder method creates a new folder on the server. Syntax: FileSystemObject.CreateFolder(name)

CreateTextFile

The CreateTextFile method creates a new text file and returns a TextStream object that can be used to read from or write to the file. Specify false on the CreateTextFile parameter to not overwrite existing files. This is an optional value. Overwriting an existing file is True by default.

Checking for and Deleting Files and Folders

The FileExists and FolderExists methods check for files and folders. The DeleteFile and DeleteFolder methods delete one or more specified folders. An error will occur if you try to delete a file and/or folder that does not exist.

Opening Text Files

Opening, reading and/or writing to a text file is a very common practice. The OpenTextFile method opens a specified file and returns a TextStream object that can be used to access the file. In the syntax above, the first parameter, filename is the only required parameter. The other three: mode, create, and format are optional. The filename specifies the name of the file to open. The mode instructs ASP regarding how to open the file. The options are 1, 2, or 8 (Reading, Writing, or Appending to an existing file). The next parameter defines whether a new file is created if the name specified does not exist. Default is false. The final parameter deals with the format. The default setting is 0 which indicates ASCII. A setting of -1 indicates Unicode and -2 indicates to use the system default.