ASP FileSystemObject



The FileSystemObject object is used to access the file system on the server.


tryitimg.gif

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

PropertyDescription
DrivesReturns a collection of all drive objects on the local computer.

Method

MethodDescription
BuildPathAppend a name After reaching the existing path.
CopyFileCopy one or more files from one location to another.
CopyFolderCopy one or more folders from one location to another.
CreateFolderCreate a new folder.
CreateTextFileCreates a text file and returns a TextStream object that can read or write the file.
DeleteFileDelete one or more specified files.
DeleteFolderDelete one or more specified folders.
DriveExistsChecks whether the specified drive exists.
FileExistsChecks whether the specified file exists.
FolderExistsChecks whether the specified folder exists.
GetAbsolutePathNameReturns the full path starting from the root of the drive for the specified path.
GetBaseNameReturns the base name of the specified file or folder.
GetDriveReturns the Drive object of the drive corresponding to the specified path.
GetDriveNameReturns the drive name of the specified path.
GetExtensionNameReturns the file extension of the last component in the specified path.
GetFileReturns a File object for the specified path.
GetFileNameReturns the file name or folder name of the last component in the specified path.
GetFolderReturns a Folder object for the specified path.
GetParentFolderNameReturns the name of the parent folder of the last component in the specified path.
GetSpecialFolderReturns the path to some Windows special folders.
GetTempNameReturns a randomly generated file or folder.
MoveFileMove one or more files from one location to another.
MoveFolderMove one or more folders from one location to another.
OpenTextFileOpens a file and returns a TextStream object for accessing this file.