Articles   Dev Forums   Personalize   Favorites   Member Login        Active Users:  98
DevASP - ASP and XML Articles, Samples, Toturials, Sample Chapters and resources for Developers Saturday, July 04, 2009
Home
Articles & Samples
Dev Search
Dev Forum
Add a Listing
Sample Chapters
Directory Feed
Link to US
Contact

Search Directory
Applications
Articles & Samples
Components
Community
Database
Developer Sites
Downloads
Hosting Services
Introduction
Knowledge Base
Sample Chapters
WebCasts

ESET
ASP Directory
Applications
Articles & Samples
Components
Developer Sites
Knowledge Base
Sample Chapters
WebCasts
XML Directory
Applications
Articles & Samples
Developer Sites
Error, Bugs & Fixes
Downloads
Introduction
Knowledge Base
Sample Chapters
WebCasts


Check File Existence with FileStystemObject

In many cases we need to check if a particular file exists on the server or not. This simple function returns true or false based on the file existence. Just pass a valid file name to the function.


<%
Option Explicit

Dim FileName

FileName = "MyFile.asp"
FileName = Server.MapPath("/Files/" & FileName)

If IsFileExists(FileName) = True  Then
 Response.Write "File exists"
Else
 Response.Write "File does not exists"
End If


' **********************************
' Function to check file Existance
' **********************************
Function IsFileExists(byVal FileName)
 
 If FileName = ""  Then
  IsFileExists = False
  Exit Function
 End If
 
 Dim objFSO
    
 Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    
 If (objFSO.FileExists( FileName ) = True  Then
  IsFileExists = True
 Else
  IsFileExists = False
 End If
  
 Set objFSO = Nothing   
End Function
%>

Have Questions? Discuss this topic in Dev Forum

DevASP - Privacy - Disclaimer
Copyright © 2008 DevASP.com