Accessing the File System
The FileSystemObject Object
The FileSystemObject object lets you create and work with files and directories on the server. For example, you can create a file, write data to it and then delete it when the file is no longer necessary. You can also determine whether or not certain files exist, as well as their locations, extensions and other information.
|
FileSystemObject Object: Methods
|
|
BuildPath
|
Adds a folder or file name to a path.
|
|
CopyFile
|
Copies a file from one location to another.
|
|
CopyFolder
|
Copies a folder and all its files from one location to another.
|
|
CreateFolder
|
Creates a new folder.
|
|
CreateTextFile
|
Creates a new text file using the TextStream object.
|
|
DeleteFile
|
Deletes a file.
|
|
DeleteFolder
|
Deletes a folder and all its files.
|
|
DriveExists
|
Determines whether or not a drive exists on the server.
|
|
FileExists
|
Determines whether or not a file exists on the server.
|
|
FolderExists
|
Determines whether or not a folder exists on the server.
|
|
GetAbsolutePathName
|
Returns the full path (from the root) for the specified folder or file.
|
|
GetBaseName
|
Returns the base name (without the extension) of the specified file or folder.
|
|
GetDrive
|
Creates an instance of the Drive object.
|
|
GetDriveName
|
Returns the drive containing the specified file.
|
|
GetExtensionName
|
Returns the extension of the specified file.
|
|
GetFile
|
Creates an instance of the File object.
|
|
GetFileName
|
Returns the file or folder name specified in a path.
|
|
GetFolder
|
Creates an instance of the Folder object.
|
|
GetParentFolderName
|
Returns the name of the parent folder for the specified file.
|
|
GetSpecialFolder
|
Returns the path of a special Windows folder. 0 returns the path for the folder containing the operating system; 1 returns the path for the folder containing libraries and drivers; 2 returns the path for the Temp folder.
|
|
GetTempName
|
Generates a temporary file or folder with a random name.
|
|
MoveFile
|
Moves a file from one location to another on the server.
|
|
MoveFolder
|
Moves a folder and all its files from one location to another on the server.
|
|
OpenTextFile
|
Opens a file using the TextStream object.
|
|
FileSystemObject Object: Properties
|
|
Drives
|
Returns a collection of Drive objects.
|
The following code determines whether or not a certain file (temp.txt) exists on the server and, if it does, deletes it:
|
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
Dim varFileSystem
Set varFileSystem=Server.CreateObject("Scripting.FileSystemObject")
If varFileSystem.FileExists("c:\inetpub\wwwroot\temp.txt")=true then
varFileSystem.DeleteFile("c:\inetpub\wwwroot\temp.txt")
End If
%>
</BODY>
</HTML>
|
Once you've created a FileSystemObject object, you can use its methods to create instances of the TextStream object, the File object, the Folder object and the Drive object. All of these have methods and properties of their own that let you create and manipulate specific files, folders and drives on the server.