Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP FileSystem Object

ASP FileSystemObject Object


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


Try it - Example

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.

Getting the Name of a Specified Drive
This example demonstrates how to get the name of a specified drive.

Getting 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.

Getting a File Extension
This example demonstrates how to get the file extension of the last component in a specified path.

Getting 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. It can also be used to get information about the file system.

The following code creates a text file (c:\test.txt), and then writes some text to it:

<%

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:

property

property Description
Drives Returns a collection of all Drive objects on the local computer.

Method

Method 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 be used to read from or write to the file.
DeleteFile Deletes one or more specified files.
DeleteFolder Deletes one or more specified folders.
DriveExists Checks whether a specified drive exists.
FileExists Checks whether a specified file exists.
FolderExists Checks whether a specified folder exists.
GetAbsolutePathName Returns the full path starting from the drive root for a specified path.
GetBaseName Returns the base name of a specified file or folder.
GetDrive Returns the Drive object corresponding to the drive in a specified path.
GetDriveName Returns the drive name of a specified path.
GetExtensionName Returns the file extension of the last component in a specified path.
GetFile Returns a File object for a specified path.
GetFileName Returns the file name or folder name of the last component in a specified path.
GetFolder Returns a Folder object for a specified path.
GetParentFolderName Returns the parent folder name of the last component in a specified path.
GetSpecialFolder Returns the paths 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.