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 / C++ / MFC
  4. CString Pathnames - backslash

CString Pathnames - backslash

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
13 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.
  • I im79

    Hi everybody, i have a problem with fullpath file names containing back slashes. The file names are saved in a CString array. The problem are the singel back slashes for ex. "C:\dir1\dir2\file.txt". Is there an easy way to substitute each "\" with "\\"? Thanks in advance :-)

    T Offline
    T Offline
    toxcct
    wrote on last edited by
    #4

    don't !!! '\\' is only the representation in "design mode" (when coding) of the character \. when you type a path in windows explorer, you type with a single **\**, don't you ?


    Don't know where to start ?
    Refer the Forums Guidelines and ask a friend

    [VisualCalc 3.0][Flags Beginner's Guide]

    1 Reply Last reply
    0
    • I im79

      Hi everybody, i have a problem with fullpath file names containing back slashes. The file names are saved in a CString array. The problem are the singel back slashes for ex. "C:\dir1\dir2\file.txt". Is there an easy way to substitute each "\" with "\\"? Thanks in advance :-)

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #5

      im79 wrote:

      Is there an easy way to substitute each "\" with "\\"?

      why you need that?

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

      I R 2 Replies Last reply
      0
      • T ThatsAlok

        im79 wrote:

        Is there an easy way to substitute each "\" with "\\"?

        why you need that?

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

        I Offline
        I Offline
        im79
        wrote on last edited by
        #6

        Hi, i need the pathname to open the file. I get the filenames list form a CFileDialoge object. I found some examples in MSDN while reading about CFile where the pathnames have double back slashes. So i think i have to change the back slashes into double backslashes :confused:

        T 1 Reply Last reply
        0
        • I im79

          Hi, i need the pathname to open the file. I get the filenames list form a CFileDialoge object. I found some examples in MSDN while reading about CFile where the pathnames have double back slashes. So i think i have to change the back slashes into double backslashes :confused:

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #7

          i repeat : No ! paths are written with double backslashes only when in a string in your source code only, like

          "C:\\myfolder\\myfile.txt"

          but this produces a paths to being like this internally :

          C:**\myfolder\**myfile.txt

          if you get a string from a CFileDialog for instance, you don't need to modify the path at all...!


          Don't know where to start ?
          Refer the Forums Guidelines and ask a friend

          [VisualCalc 3.0][Flags Beginner's Guide]

          I 1 Reply Last reply
          0
          • T ThatsAlok

            im79 wrote:

            Is there an easy way to substitute each "\" with "\\"?

            why you need that?

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

            R Offline
            R Offline
            realJSOP
            wrote on last edited by
            #8

            If you can help the man, do so. WHY he wants to do it is not important at all.

            "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." - Jason Jystad, 10/26/2001

            T T 2 Replies Last reply
            0
            • R realJSOP

              If you can help the man, do so. WHY he wants to do it is not important at all.

              "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." - Jason Jystad, 10/26/2001

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #9

              helping a guy doesn't always provide a working piece of code ! in this case, what the OP needed is useless, simply he didn't understand that double backslashes exists only because the backslash is the escapment character... i think what Alok did was to make the OP explicit his real need, and then Alok could explain him that he was wrong...


              Don't know where to start ?
              Refer the Forums Guidelines and ask a friend

              [VisualCalc 3.0][Flags Beginner's Guide]

              R 1 Reply Last reply
              0
              • T toxcct

                helping a guy doesn't always provide a working piece of code ! in this case, what the OP needed is useless, simply he didn't understand that double backslashes exists only because the backslash is the escapment character... i think what Alok did was to make the OP explicit his real need, and then Alok could explain him that he was wrong...


                Don't know where to start ?
                Refer the Forums Guidelines and ask a friend

                [VisualCalc 3.0][Flags Beginner's Guide]

                R Offline
                R Offline
                realJSOP
                wrote on last edited by
                #10

                Helping someone doesn't necessarily include providing a piece of working code. Asking why someone wants to do something is irrelevant. If someone can't actually help, they should just STFU and let someone else step up. The post I responded too has already generated three needless replies and just makes noise that the OP has to wade through.

                "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." - Jason Jystad, 10/26/2001

                1 Reply Last reply
                0
                • R realJSOP

                  If you can help the man, do so. WHY he wants to do it is not important at all.

                  "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." - Jason Jystad, 10/26/2001

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #11

                  John Simmons / outlaw programmer wrote:

                  If you can help the man, do so. WHY he wants to do it is not important at all.

                  Sir, actually just want to know root cause of the problem.. numerous times people here at forums ask thing which they don't actually need! which create problem to them at later stage.. so to solve there problem.. some time people ask what actually they need.. Just like we do in URS/SRS phase.. You very well know that.  secondly, if you see.. that guy require double slashes which you see he don't need! hope i clear my point.. if any thing wrong... i am sorry!

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

                  1 Reply Last reply
                  0
                  • T toxcct

                    i repeat : No ! paths are written with double backslashes only when in a string in your source code only, like

                    "C:\\myfolder\\myfile.txt"

                    but this produces a paths to being like this internally :

                    C:**\myfolder\**myfile.txt

                    if you get a string from a CFileDialog for instance, you don't need to modify the path at all...!


                    Don't know where to start ?
                    Refer the Forums Guidelines and ask a friend

                    [VisualCalc 3.0][Flags Beginner's Guide]

                    I Offline
                    I Offline
                    im79
                    wrote on last edited by
                    #12

                    Hi toxcct, hi everybody, i' get the pathname CString with CFileDialog and then i pass it to function casts the CString to char* then it opens the file with fopenf. The C function fopenf is used because of a legacy code with a lot of fscanf calls with a specific foramt. I'm forecd to use theh old code for many reasons. Now, the orignal code workes with double backslashes, and if don't change the single backslashes to double, it won't work. Now i'm more confused :confused: Is there a difference when useing CFile::open() instead? In that case i need to rewrite the whole fscanf block :~ Thank u all for u help :)

                    T 1 Reply Last reply
                    0
                    • I im79

                      Hi toxcct, hi everybody, i' get the pathname CString with CFileDialog and then i pass it to function casts the CString to char* then it opens the file with fopenf. The C function fopenf is used because of a legacy code with a lot of fscanf calls with a specific foramt. I'm forecd to use theh old code for many reasons. Now, the orignal code workes with double backslashes, and if don't change the single backslashes to double, it won't work. Now i'm more confused :confused: Is there a difference when useing CFile::open() instead? In that case i need to rewrite the whole fscanf block :~ Thank u all for u help :)

                      T Offline
                      T Offline
                      toxcct
                      wrote on last edited by
                      #13

                      damn, don't you understand ??????? well, i sum up, but it's my last explanation ! 1. you choose your file with the CFileDialog 2. you then get the file path into a CString object 3. you pass this CString object directly to fopen() ! there's no need to change a backslash into double backslashes, because you need this only when you hardcode strings in your source code (because the \ is the character escapment, and '\\' is the ascii code for the \ character) !!!


                      Don't know where to start ?
                      Refer the Forums Guidelines and ask a friend

                      [VisualCalc 3.0][Flags Beginner's Guide]

                      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