SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Determining the existence of file or directory by using FileSystemObject in ASP

We can check whether file of folder exists at a location by using file system object ( FileSystemObject). This is often required to check the existence of a file or directory before using, otherwise system will generate an error message which is not good to display to the visitors. So before using any file or folder we can check the status of them.

FileSystemObject or fso uses physical path of the file or folder to check the existence so before using this we have to convert the virtual path to physical path for our folders or files by using server.mappath object.

We will use one variable to hold the instance of the FileSystemObject and using this we will check the existence of the file or folder.

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")


Next we will use the If Then Else statement to check the condition of the file or folder.

If objFSO.FolderExists(Server.MapPath("db")) Then
Response.Write "Folder Exists"
else
Response.Write "Folder does not exit"
End if


Here “db” is the name of the folder we are checking the existence. We have used the command Server.MapPath to change the virtual path to physical path of the folder db.

We can print the command based the response of the object ( True or False ) and display the message accordingly.

Same way we can use objFSO.FileExists to check the existence of a file at any location.
Further readings
Server.MapPath to convert virtual path to physical path of files and directory.
FileSystemObject:Checking file or folder exist by using File system object .
Getting the file name from full path of the current running script in ASP.
Getting the file extension and file name by using FSO
Deleting file by using DeleteFile in FSO
Getting the Last updating and creation date and time of a file.
Listing all files present inside a folder using FileSystemObject
Reading data from a text file using File System Object
Writing data to a text file using File System Object
Read & Writing data to a text file: Developing a page hit counter
Appending data to a text file: Storing emails in a text file
 
Scripts
PHP
JavaScript
All ASP Tutorials
File Management
MapPath
FileSystemObject
append
name
Updating Time
Listing all files
Reading file
Writing file
Read & Write
File type
Delete File
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.