user435838
user435838

Reputation: 1

Classic ASP getPathName and getName Error

I usually developed website using PHP. But now i have to using ASP Classic because my client already have a website then i have to maintenance the website. i already move all of the website to my new hosting. But there is error on this code :

cPath=getPathName(Server.mappath(Request.ServerVariables("PATH_INFO")))

The error message is :

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'getPathName'

Some error display when call getName code.

Please help me what should i do.

Upvotes: 0

Views: 468

Answers (1)

Shadow Wizzard
Shadow Wizzard

Reputation: 66398

Classic ASP or VBScript do not have equivalent to the PHP getPathName() and getName() functions as far as I can tell.

I wasn't able to understand what's the meaning of getPathName() when it's given a string and actually I don't think it exists, so just have:

cPath = Server.MapPath(Request.ServerVariables("PATH_INFO"))

And the variable will contain the full physical path to the currently executing ASP file.

As for getName() you can write custom function:

Function GetOnlyName(filePath)
    Dim slashIndex
    slashIndex = InStrRev(filePath, "\")
    If slashIndex<1 Then
        slashIndex = InStrRev(filePath, "/")
    End If
    If slashIndex>0 Then
        ExtractFileName = Mid(filePath, slashIndex + 1, Len(filePath) - slashIndex + 1)
    Else  
        ExtractFileName = filePath
    End If
End Function

Then use it like this:

cName = GetOnlyName(Server.MapPath(Request.ServerVariables("PATH_INFO")))

And the variable will contain only the name of the ASP file.

For the record, to avoid confusing Type Mismatch errors, always put this on top of your scripts:

Option Explicit

Then always declare all your variable using Dim statement, like in the function above. Having this, trying to use getPathName would give "variable undefined" error which is much more meaningful.

Upvotes: 1

Related Questions