ASP FileSystemObject
The FileSystemObject object is used to access the file system on the server.
Try it - Example
Does the file specified exist?
This example demonstrates how to check whether a file exists.
Does the specified folder exist?
This example demonstrates how to check whether a folder exists.
Does the specified drive exist?
This example demonstrates how to check whether a drive exists.
Get the name of a specified drive
This example demonstrates how to get the name of a specified drive.
Get the name of the parent folder of a specified path
This example demonstrates how to get the name of the parent folder of a specified path.
Get the file name
This example demonstrates how to get the file name of the last component in the specified path.
Get the file extension
This example demonstrates how to get the file extension of the last component in the specified path.
Get the base name of a file or folder
This example demonstrates how to get the base name of a file or folder in a specified path.
FileSystemObject Object
The FileSystemObject object is used to access the file system on the server.
This object can operate on files, folders and directory paths. File system information can also be obtained through this object.
The following code will create a text file (c:\test.txt), and then write some text to this file:
dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("c:\test.txt",true)
fname.WriteLine("Hello World!")
fname.Close
set fname=nothing
set fs=nothing
%>
The properties and methods of the FileSystemObject object are described as follows:
Properties
Property | Description |
---|---|
Drives | Returns a collection of all drive objects on the local computer. |
Method
Method | Description |
---|---|
BuildPath | Append a name After reaching the existing path. |
CopyFile | Copy one or more files from one location to another. |
CopyFolder | Copy one or more folders from one location to another. |
CreateFolder | Create a new folder. |
CreateTextFile | Creates a text file and returns a TextStream object that can read or write the file. |
DeleteFile | Delete one or more specified files. |
DeleteFolder | Delete one or more specified folders. |
DriveExists | Checks whether the specified drive exists. |
FileExists | Checks whether the specified file exists. |
FolderExists | Checks whether the specified folder exists. |
GetAbsolutePathName | Returns the full path starting from the root of the drive for the specified path. |
GetBaseName | Returns the base name of the specified file or folder. |
GetDrive | Returns the Drive object of the drive corresponding to the specified path. |
GetDriveName | Returns the drive name of the specified path. |
GetExtensionName | Returns the file extension of the last component in the specified path. |
GetFile | Returns a File object for the specified path. |
GetFileName | Returns the file name or folder name of the last component in the specified path. |
GetFolder | Returns a Folder object for the specified path. |
GetParentFolderName | Returns the name of the parent folder of the last component in the specified path. |
GetSpecialFolder | Returns the path to some Windows special folders. |
GetTempName | Returns a randomly generated file or folder. |
MoveFile | Move one or more files from one location to another. |
MoveFolder | Move one or more folders from one location to another. |
OpenTextFile | Opens a file and returns a TextStream object for accessing this file. |