Your source for ASP-related frequently asked questions and answers! : ASP FAQS : FileSystemObject

Question: How do I find out if a file exists?


Set FSO = Server.CreateObject("Scripting.FileSystemObject")
If FSO.FileExists( Server.MapPath( "" ) ) Then
    ... file exists ...
    ... it does not ...
End If

The argument to the FileExists method must be the FULL PATH to a file somewhere on your local system (or LAN, if applicable). You can either give the path explicitly, as in

If FSO.FileExists( "x:\nastyComments\crossposts\answer3.txt" ) Then

or you can give a path that is relative to the location of the currently executing ASP page via something like

If FSO.FileExists( Server.MapPath( "../images/uglyface.jpg" ) ) Then

See other FAQs in the category for more on filenames, etc.

FAQ posted by Bill Wilkinson at 11/1/2000 4:22:14 PM to the FileSystemObject category. This FAQ has been viewed 53,170 times.

Copyright 2018 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers