Name

GetBaseName (FileSystemObject Object) — fsoObj .GetBaseName( strPath )

Synopsis

Extracts the name of a file—minus any file extension—from a full file path.

Parameters

strPath

A string representing the full file path of a given file whose base name you want to retrieve

Example

<%

' Dimension local variables. 
Dim fsoObject   ' FileSystemObject
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
                "Scripting.FileSystemObject")
' Using the GetBaseName method, retrieve the base 
' names of several path strings. 
' This example returns "searchstart" as the base name.
Response.Write fsoObject.GetBaseName( _
               "/apps/search/searchstart.asp")
' This example returns "search" as the base name.
Response.Write fsoObject.GetBaseName("/apps/search/")
' This example returns "search" as the base name.
Response.Write fsoObject.GetBaseName("/apps/search")
' This example returns "nofile" as the base name--even
' though the nofile.txt file does not exist.
fsoObject.GetBaseName("/apps/search/nofile.txt")
. . . [additional code]

%>

Notes

GetBaseName attempts to retrieve the base name for a file from a path string. If the last element in the path string is a folder, the folder name is returned—even if you include a closing slash (/) or backslash (\) character. The path string is not checked for its validity or its existence as a real path on the server. The method just looks at the path as a string. For this reason, the association of this method with the FileSystemObject object ...

Get ASP in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.