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. spliting file name

spliting file name

Scheduled Pinned Locked Moved C#
help
7 Posts 6 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.
  • T Offline
    T Offline
    tanweer
    wrote on last edited by
    #1

    i ma copying a file from a location to a destination but now i m unale to separate the file name that is come in with the whole path of the file please help me

    S OriginalGriffO L realJSOPR 4 Replies Last reply
    0
    • T tanweer

      i ma copying a file from a location to a destination but now i m unale to separate the file name that is come in with the whole path of the file please help me

      S Offline
      S Offline
      sanforjackass
      wrote on last edited by
      #2

      make (for)loop that run in reverse searching for('\\')char then(break)

      OriginalGriffO 1 Reply Last reply
      0
      • T tanweer

        i ma copying a file from a location to a destination but now i m unale to separate the file name that is come in with the whole path of the file please help me

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        There are quite a few ways to do this, it will depend on what file information you have available. String: Use String.LastIndexOf to find the final '\' character, and String.Substring to extract just the file name. Or just use Path.GetFileName(string s) to extract it from any string. FileInfo: Use FileInfo.Name to extract just the file name. There are probably others, but these should cover most cases.

        All those who believe in psycho kinesis, raise my hand. My :badger:'s gonna unleash hell on your ass. :badger:tastic!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • S sanforjackass

          make (for)loop that run in reverse searching for('\\')char then(break)

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Why? There is a string.LastIndexOf method...

          All those who believe in psycho kinesis, raise my hand. My :badger:'s gonna unleash hell on your ass. :badger:tastic!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • T tanweer

            i ma copying a file from a location to a destination but now i m unale to separate the file name that is come in with the whole path of the file please help me

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Read up on the Path class; it holds everything you could want about file path strings. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
            [The QA section does it automatically now, I hope we soon get it on regular forums as well]


            P 1 Reply Last reply
            0
            • T tanweer

              i ma copying a file from a location to a destination but now i m unale to separate the file name that is come in with the whole path of the file please help me

              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #6

              You can do it one of two ways:

              string[] pathParts = myPath.Split('\\');

              and you'll end up with an array of strings that represent the various components. Or, you can use the various System.Path.IO.GetXXXXX methods.

              .45 ACP - because shooting twice is just silly
              -----
              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

              1 Reply Last reply
              0
              • L Luc Pattyn

                Read up on the Path class; it holds everything you could want about file path strings. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
                [The QA section does it automatically now, I hope we soon get it on regular forums as well]


                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                That is the correct answer.

                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