ASP FileSystemObjectObject


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


Examples

Try it Yourself - Examples

Does the specified file 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 a specified path.

Get the file extension
This example demonstrates how to get the file extension of the last component in a 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 a server.

This object can operate on files, folders, and directory paths. It can also be used to obtain file system information.

The following code creates a text file (c:\test.txt) and then writes some text to the 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 below:

Properties

Properties Description
Drives Returns a collection of all drive objects on the local computer.

Methods

Methods Description
BuildPath Appends a name to an existing path.
CopyFile Copies one or more files from one location to another.
CopyFolder Copies one or more folders from one location to another.
CreateFolder Creates a new folder.
CreateTextFile Creates a text file and returns a TextStream object that can read from or write to the file.
DeleteFile Deletes one or more specified files.
DeleteFolder Deletes 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 complete 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 corresponding to the drive for 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 parent folder name of the last component in the specified path.
GetSpecialFolder Returns the path of certain special Windows folders.
GetTempName Returns a randomly generated file or folder.
MoveFile Moves one or more files from one location to another.
MoveFolder Moves one or more folders from one location to another.
OpenTextFile Opens a file and returns a TextStream object for accessing the file.

Other Extensions