Thursday, March 3, 2011

Scripting.FileSystemObject.FileExists always returns false

I'm attempting to check that a file exists before including it with Server.Execute in Classic ASP. While FileExists() returns False, Server.Execute successfully executes the file. Both calls use the exact same file path.

Why does this happen and how can I work around it?

From stackoverflow
  • Are you using a Network Path? If so, try without that, perhaps mapping a drive.

    AnthonyWJones : Mapped drives are not available in ASP
  • I suspect you're passing a relative path (eg., "/Subfolder/Page.asp"). You'd need to Server.MapPath that for the call into FileExists - which needs an absolute path (eg., "C:\inetpub\wwwroot\Subfolder\Page.asp").

    <%
    Dim path : path = "/Admin/default.asp"
    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
    
    If fso.FileExists(Server.MapPath(path)) Then
       Server.Execute(path)
    Else
       Response.Write "The path " & path & " does not exist."
    End If
    
    Set fso = Nothing
    %>
    

0 comments:

Post a Comment