Generic way to extract filename from path independent on platform

Discussion in 'ASP General' started by PeterB, Feb 9, 2005.

  1. PeterB

    PeterB Guest

    Hello!

    I'm using the following method to retrieve the filname from a full server
    path:

    <%
    sub getfname(strPath)
    Dim fName
    fName = Mid(strPath,InStrRev(strPath,"\")+1)
    'fName = strPath
    Response.Write( fName )
    end sub
    %>

    However this only works on Windows systems as it checks for backslash. Is
    there a more generic way to do this, or should I check for both backslash
    and slash in the path?

    thanks,

    Peter
     
    PeterB, Feb 9, 2005
    #1
    1. Advertising

  2. PeterB

    PeterB Guest

    A / perhaps? Unix notatio, there are Unix/Linux modules for .NET out there
    so it would be possible to run an ASP site on a linux-machine...

    / Peter


    "Curt_C [MVP]" <software_AT_darkfalz.com> skrev i meddelandet
    news:...
    > huh? What else would it be if not a \
    >
    >
    > --
    > Curt Christianson
    > Site & Scripts: http://www.Darkfalz.com
    > Blog: http://blog.Darkfalz.com
    >
    >
    > "PeterB" <> wrote in message
    > news:%...
    >> Hello!
    >>
    >> I'm using the following method to retrieve the filname from a full server
    >> path:
    >>
    >> <%
    >> sub getfname(strPath)
    >> Dim fName
    >> fName = Mid(strPath,InStrRev(strPath,"\")+1)
    >> 'fName = strPath
    >> Response.Write( fName )
    >> end sub
    >> %>
    >>
    >> However this only works on Windows systems as it checks for backslash. Is
    >> there a more generic way to do this, or should I check for both backslash
    >> and slash in the path?
    >>
    >> thanks,
    >>
    >> Peter
    >>

    >
    >
     
    PeterB, Feb 10, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9l?=

    Extract filename from a filename typed by user

    =?Utf-8?B?Sm9l?=, Aug 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,035
    Travis Murray
    Aug 24, 2004
  2. MK
    Replies:
    1
    Views:
    842
    Peter Hansen
    Jun 25, 2003
  3. Gandalf
    Replies:
    1
    Views:
    307
    Lawrence Oluyede
    Aug 18, 2004
  4. =?iso-8859-1?B?QW5kcuk=?=
    Replies:
    8
    Views:
    386
    =?iso-8859-1?B?QW5kcuk=?=
    May 1, 2007
  5. Jan Thomä
    Replies:
    15
    Views:
    2,562
    Jan Thomä
    Feb 19, 2009
Loading...

Share This Page