how to get only the name of the file, not the whole path?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben

    #1

    how to get only the name of the file, not the whole path?

    Hi,

    i need the filename of files located in a directory.

    I use this:
    Directory.GetFi les(Server.MapP ath("~/mydirectory/")
    For Each fileName In fileEntries
    name=fileName
    next

    but this guves the full path. Any way to get only the filename? Of course i
    can use substring, but does it exist a function?
    Thanks
    Ben



  • Lloyd Sheen

    #2
    Re: how to get only the name of the file, not the whole path?


    "Ben" <be@fd.dcwrot e in message
    news:OGATUE1QJH A.3384@TK2MSFTN GP05.phx.gbl...
    Hi,
    >
    i need the filename of files located in a directory.
    >
    I use this:
    Directory.GetFi les(Server.MapP ath("~/mydirectory/")
    For Each fileName In fileEntries
    name=fileName
    next
    >
    but this guves the full path. Any way to get only the filename? Of course
    i can use substring, but does it exist a function?
    Thanks
    Ben
    >
    >
    >
    Check out the functions in the System.IO.Path namespace. This namespace has
    all functions to manipulate file names etc.

    LS

    Comment

    • Eliyahu Goldin

      #3
      Re: how to get only the name of the file, not the whole path?

      FileInfo.Name

      --
      Eliyahu Goldin,
      Software Developer
      Microsoft MVP [ASP.NET]



      "Lloyd Sheen" <a@b.cwrote in message
      news:eZ%23ooH1Q JHA.2228@TK2MSF TNGP06.phx.gbl. ..
      >
      "Ben" <be@fd.dcwrot e in message
      news:OGATUE1QJH A.3384@TK2MSFTN GP05.phx.gbl...
      >Hi,
      >>
      >i need the filename of files located in a directory.
      >>
      >I use this:
      >Directory.GetF iles(Server.Map Path("~/mydirectory/")
      >For Each fileName In fileEntries
      >name=fileNam e
      >next
      >>
      >but this guves the full path. Any way to get only the filename? Of course
      >i can use substring, but does it exist a function?
      >Thanks
      >Ben
      >>
      >>
      >>
      >
      Check out the functions in the System.IO.Path namespace. This namespace
      has all functions to manipulate file names etc.
      >
      LS

      Comment

      • Alexey Smirnov

        #4
        Re: how to get only the name of the file, not the whole path?

        On Nov 10, 5:26 pm, "Ben" <b...@fd.dcwrot e:
        Hi,
        >
        i need the filename of files located in a directory.
        >
        I use this:
        Directory.GetFi les(Server.MapP ath("~/mydirectory/")
        For Each fileName In fileEntries
        name=fileName
        next
        >
        but this guves the full path. Any way to get only the filename? Of coursei
        can use substring, but does it exist a function?
        Thanks
        Ben
        ' Create a reference to the current directory.
        Dim di As New DirectoryInfo(E nvironment.Curr entDirectory)
        ' Create an array representing the files in the current
        directory.
        Dim fi As FileInfo() = di.GetFiles()
        Console.WriteLi ne("The following files exist in the current
        directory:")
        ' Print out the names of the files in the current directory.
        Dim fiTemp As FileInfo
        For Each fiTemp In fi
        Console.WriteLi ne(fiTemp.Name)
        Next fiTemp

        http://msdn.microsoft.com/en-us/libr...info.name.aspx

        Hope this helps

        Comment

        Working...