Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Get only file name from str

Get only file name from str

Scheduled Pinned Locked Moved C#
question
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    papa80
    wrote on last edited by
    #1

    Hi How can i get only the file name from string who consist full path? best regards

    when i want to read something good just seat and type it

    L B 2 Replies Last reply
    0
    • P papa80

      Hi How can i get only the file name from string who consist full path? best regards

      when i want to read something good just seat and type it

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      fullPath.Substring(fullPath.LastIndexOf('\\')+1) Is the MSDN really so hard to read? :sigh:

      N 1 Reply Last reply
      0
      • L Lost User

        fullPath.Substring(fullPath.LastIndexOf('\\')+1) Is the MSDN really so hard to read? :sigh:

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        Greeeg wrote:

        Is the MSDN really so hard to read?

        No it isn't. Have you read it? System.IO.Path.GetFileName


        only two letters away from being an asset

        P L 2 Replies Last reply
        0
        • N Not Active

          Greeeg wrote:

          Is the MSDN really so hard to read?

          No it isn't. Have you read it? System.IO.Path.GetFileName


          only two letters away from being an asset

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          So what? Both solutions will work. My point is that it can't be so hard to open up the MSDN (local or online), go to the string or IO members and look if there's a function that fits my needs. Nichts für ungut ;)

          D 1 Reply Last reply
          0
          • N Not Active

            Greeeg wrote:

            Is the MSDN really so hard to read?

            No it isn't. Have you read it? System.IO.Path.GetFileName


            only two letters away from being an asset

            P Offline
            P Offline
            papa80
            wrote on last edited by
            #5

            i am sorry but i really have not time to read it.Thank's for help

            when i want to read something good just seat and type it

            D 1 Reply Last reply
            0
            • P papa80

              Hi How can i get only the file name from string who consist full path? best regards

              when i want to read something good just seat and type it

              B Offline
              B Offline
              BoneSoft
              wrote on last edited by
              #6

              string file = System.IO.Path.GetFileName(path);


              Try code model generation tools at BoneSoft.com.

              1 Reply Last reply
              0
              • L Lost User

                So what? Both solutions will work. My point is that it can't be so hard to open up the MSDN (local or online), go to the string or IO members and look if there's a function that fits my needs. Nichts für ungut ;)

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                You're solution will work, so long as the path seperatation character is a backslash. This is not always the case and is not platform-independent. Using the correct method, pointed to by Mark, will work no matter what the platform or seperation character happens to be.

                Dave Kreskowiak Microsoft MVP - Visual Basic

                1 Reply Last reply
                0
                • P papa80

                  i am sorry but i really have not time to read it.Thank's for help

                  when i want to read something good just seat and type it

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  papa80 wrote:

                  i am sorry but i really have not time to read it.

                  That's funny!! Looking it up on MSDN, or hitting F1 in Visual Studio, probably would have taken you 3 minutes to find the answer. How long did it take you to post the question on CP and wait for answer?

                  Dave Kreskowiak Microsoft MVP - Visual Basic

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups