<!--
Useful Routines to Parse Path Names
Jon Vote, Idioma Software Inc.
03/2002
www.idioma-software.com
This ASP Program Demonstrates Path Parsing Routines:
JustThePath - Strips the FileName, returns only the path name.
JustTheFile - Strips the Path name, returns only the file name.
StripExt - Strips File Extension
GetExt - Gets File Extension
-->
<%@ LANGUAGE="VBSCRIPT" %>
<!--
Useful Routines for Parsing Path Names
Jon Vote, Idioma Software Inc.
03/2002
www.idioma-software.com
-->
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Useful Path Names and How to Parse Them</TITLE>
</HEAD>
<BODY>
<Center><H3>Here are some useful path names and some routines to parse them!</H3></Center>
<Center>
This ASP Example was provided by <A Href="http://www.idioma-software.com">Idioma Software Inc.</A><BR><BR>
</Center>
<BlockQuote>
<B>This ASP Program Demonstrates Path Parsing Routines:</B><BR>
<UL>
<LI>JustThePath - Strips the FileName, returns only the path name.
<LI>JustTheFile - Strips the Path name, returns only the file name.
<LI>StripExt - Strips File Extension
<LI>GetExt - Gets File Extension
</UL>
</BlockQuote>
<%
PaintScreen
%>
</BODY>
</HTML>
<% 'PaintScreen - Paint the screen to demonstrate
'how to use the parsing routines.
Private Sub PaintScreen
Dim strPath
%>
<TABLE Border=2 Align=Center>
<!-- Request.ServerVariables("URL") -->
<TR>
<TD ColSpan=2 Align=Center><B>Request.ServerVariables("URL")</B></TD>
</TR>
<% ParseThisPath(Request.ServerVariables("URL")) %>
<!-- Request.ServerVariables("PATH_INFO") -->
<TR>
<TD ColSpan=2 Align=Center><B>Request.ServerVariables("PATH_INFO")</B></TD>
</TR>
<% ParseThisPath(Request.ServerVariables("PATH_INFO")) %>
<!-- Request.ServerVariables("PATH_TRANSLATED") -->
<TR>
<TD ColSpan=2 Align=Center><B>Request.ServerVariables("PATH_TRANSLATED")</B></TD>
</TR>
<% ParseThisPath(Request.ServerVariables("PATH_TRANSLATED")) %>
<!-- Request.ServerVariables("APPL_PHYSICAL_PATH") -->
<TR>
<TD ColSpan=2 Align=Center><B>Request.ServerVariables("APPL_PHYSICAL_PATH")</B></TD>
</TR>
<% ParseThisPath(Request.ServerVariables("APPL_PHYSICAL_PATH")) %>
<!-- Server.MapPath("/") -->
<TR>
<TD ColSpan=2 Align=Center><B>Server.MapPath("/")</B></TD>
</TR>
<% ParseThisPath(Server.MapPath("/")) %>
</TABLE>
<%
End Sub
%>
<%
Private Sub ParseThisPath(ByVal strPath)
%>
<TR>
<TD>FullPath:</TD>
<TD><%=strPath%></TD>
</TR>
<TR>
<TD>JustThePath:</TD>
<TD><%=JustThePath(strPath)%></TD>
</TR>
<TR>
<TD>JustTheFile</TD>
<TD><%=JustTheFile(strPath)%></TD>
</TR>
<TR>
<TD>StripExt</TD>
<TD><%=StripExt(strPath)%></TD>
</TR>
<TR>
<TD>GetExt</TD>
<TD><%=GetExt(strPath)%></TD>
</TR>
<TR>
</TR>
<%
End Sub
%>
<%
'************************************************
'** - These routines can be used to parse
'** - path names. Normally these routines would
'** - be put in an include file to use in many projects.
'************************************************
%>
<% 'JustThePath - Strips the FileName, returns only the path name.
Public Function JustThePath(ByVal strPathName)
Dim intPos
intPos = InStrRev(strPathName, "\")
If intPos = 0 then
IntPos = InStrRev(strPathName, "/")
End If
If intPos = 0 then
IntPos = InStrRev(strPathName, ":")
End If
If intPos > 0 then
JustThePath = Left(strPathName, intPos)
Else
JustThePath = ""
End If
End Function
%>
<% 'JustTheFile - Strips the Path name, returns only the file name.
Public Function JustTheFile(ByVal strPathName)
Dim intPos
intPos = InStrRev(strPathName, "\")
If intPos = 0 then
IntPos = InStrRev(strPathName, "/")
End If
If intPos = 0 then
IntPos = InStrRev(strPathName, ":")
End If
If intPos > 0 then
JustTheFile = Mid(strPathName, intPos+1)
Else
JustTheFile = strPathName
End If
End Function
%>
<% 'StripExt - Strips File Extension
Public Function StripExt(ByVal strPathName)
Dim intDotPos
intDotPos = InStr(strPathName, ".")
If intDotPos > 0 then
StripExt = Left(strPathName, intDotPos-1)
Else
StripExt = strPathName
End If
End Function
%>
<% 'GetExt - Gets File Extension
Public Function GetExt(ByVal strPathName)
Dim intDotPos
intDotPos = InStr(strPathName, ".")
If intDotPos > 0 then
GetExt = Mid(strPathName, intDotPos+1)
Else
GetExt = ""
End If
End Function
%>