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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Determining the exact directory path [modified]

Determining the exact directory path [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
15 Posts 6 Posters 1 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.
  • C capricious_001

    Hi there, I am trying to use CreateFile to open up a file handle however in some instances it doesnt work. Is there a way to convert a file location string into its exact case-sensitive string? For example.

    lszLogFile = "C:\\TeSt\\TeSt.txt";

    HANDLE hLogFile = NULL;
    hLogFile = CreateFile(lszLogFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

    lszLogFile is the actual parameter that works with create file and a handle is created, however if

    lszLogFile = "C:\\test\\test.txt";

    Then a handle will not be created. Is there a way to find out what the actual Directory string is? Thanks guys, Robbie -- modified at 13:10 Monday 19th June, 2006 Added the extra backslashes, and no that wasnt the problem.

    M Offline
    M Offline
    Maxwell Chen
    wrote on last edited by
    #3

    capricious_001 wrote:

    lszLogFile = "C:\\test\test.txt";

    Should be:

    lszLogFile = "C:\\test**\\**test.txt";


    Maxwell Chen

    T 1 Reply Last reply
    0
    • C capricious_001

      Hi there, I am trying to use CreateFile to open up a file handle however in some instances it doesnt work. Is there a way to convert a file location string into its exact case-sensitive string? For example.

      lszLogFile = "C:\\TeSt\\TeSt.txt";

      HANDLE hLogFile = NULL;
      hLogFile = CreateFile(lszLogFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

      lszLogFile is the actual parameter that works with create file and a handle is created, however if

      lszLogFile = "C:\\test\\test.txt";

      Then a handle will not be created. Is there a way to find out what the actual Directory string is? Thanks guys, Robbie -- modified at 13:10 Monday 19th June, 2006 Added the extra backslashes, and no that wasnt the problem.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #4

      capricious_001 wrote:

      lszLogFile = "C:\\TeSt\TeSt.txt";

      This should be:

      lszLogFile = "C:\\TeSt\\TeSt.txt";

      capricious_001 wrote:

      Then a handle will not be created.

      Why not? Have you checked the return value of GetLastError()?

      capricious_001 wrote:

      Is there a way to find out what the actual Directory string is?

      It's whatever value you have assigned to lszLogFile.


      "The largest fire starts but with the smallest spark." - David Crow

      "Judge not by the eye but by the heart." - Native American Proverb

      C 1 Reply Last reply
      0
      • M Maxwell Chen

        capricious_001 wrote:

        lszLogFile = "C:\\test\test.txt";

        Should be:

        lszLogFile = "C:\\test**\\**test.txt";


        Maxwell Chen

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

        where ? i can't see any difference ?! :~ :rolleyes:;P


        TOXCCT >>> GEII power

        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

        M D 2 Replies Last reply
        0
        • T toxcct

          where ? i can't see any difference ?! :~ :rolleyes:;P


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          M Offline
          M Offline
          Maxwell Chen
          wrote on last edited by
          #6

          The gap is too large! ;P


          Maxwell Chen

          T 1 Reply Last reply
          0
          • M Maxwell Chen

            The gap is too large! ;P


            Maxwell Chen

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

            are you sure he will understand though ? ;) i'm sure some people still don't see the tip :cool:


            TOXCCT >>> GEII power

            [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

            M 1 Reply Last reply
            0
            • D David Crow

              capricious_001 wrote:

              lszLogFile = "C:\\TeSt\TeSt.txt";

              This should be:

              lszLogFile = "C:\\TeSt\\TeSt.txt";

              capricious_001 wrote:

              Then a handle will not be created.

              Why not? Have you checked the return value of GetLastError()?

              capricious_001 wrote:

              Is there a way to find out what the actual Directory string is?

              It's whatever value you have assigned to lszLogFile.


              "The largest fire starts but with the smallest spark." - David Crow

              "Judge not by the eye but by the heart." - Native American Proverb

              C Offline
              C Offline
              capricious_001
              wrote on last edited by
              #8

              lol nono, the path directory is correct. I just forgot the extra backslash in this example. I tested it. having lszLogFile = "C:\\TeSt\\TeSt.txt"; works rather than having all the characters as lower case. So really the question is how do i retreive the case sensitive file path of that file -- modified at 13:09 Monday 19th June, 2006 I wrote that piece of code in my original post on the fly. I hate copying and pasting my code because its just too much too read.

              D 1 Reply Last reply
              0
              • C capricious_001

                Hi there, I am trying to use CreateFile to open up a file handle however in some instances it doesnt work. Is there a way to convert a file location string into its exact case-sensitive string? For example.

                lszLogFile = "C:\\TeSt\\TeSt.txt";

                HANDLE hLogFile = NULL;
                hLogFile = CreateFile(lszLogFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

                lszLogFile is the actual parameter that works with create file and a handle is created, however if

                lszLogFile = "C:\\test\\test.txt";

                Then a handle will not be created. Is there a way to find out what the actual Directory string is? Thanks guys, Robbie -- modified at 13:10 Monday 19th June, 2006 Added the extra backslashes, and no that wasnt the problem.

                M Offline
                M Offline
                Maxwell Chen
                wrote on last edited by
                #9

                capricious_001 wrote:

                lszLogFile = "C:\\test\\test.txt";

                OK. I've read your modified post. Now it looks like a "chicken-and-egg" question though.

                capricious_001 wrote:

                Then a handle will not be created. Is there a way to find out what the actual Directory string is?

                To retrieve the so-called *exact* file path, you need a valid file handle and pass the valid handle into some API. To get a file handle without knowing the *exact* case-sensitive path (in your case), you can only input the path in case-insensitive form which results in failure (in your case). Anyway, my system works very well with both your code snippets. :->


                Maxwell Chen

                C 1 Reply Last reply
                0
                • T toxcct

                  are you sure he will understand though ? ;) i'm sure some people still don't see the tip :cool:


                  TOXCCT >>> GEII power

                  [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                  M Offline
                  M Offline
                  Maxwell Chen
                  wrote on last edited by
                  #10

                  I'm confused too ... :doh:


                  Maxwell Chen

                  1 Reply Last reply
                  0
                  • M Maxwell Chen

                    capricious_001 wrote:

                    lszLogFile = "C:\\test\\test.txt";

                    OK. I've read your modified post. Now it looks like a "chicken-and-egg" question though.

                    capricious_001 wrote:

                    Then a handle will not be created. Is there a way to find out what the actual Directory string is?

                    To retrieve the so-called *exact* file path, you need a valid file handle and pass the valid handle into some API. To get a file handle without knowing the *exact* case-sensitive path (in your case), you can only input the path in case-insensitive form which results in failure (in your case). Anyway, my system works very well with both your code snippets. :->


                    Maxwell Chen

                    C Offline
                    C Offline
                    capricious_001
                    wrote on last edited by
                    #11

                    I used GetLastError() and figured out that it was an issue with my type-casting, but I fixed it lol. Thanks for the help.

                    1 Reply Last reply
                    0
                    • T toxcct

                      where ? i can't see any difference ?! :~ :rolleyes:;P


                      TOXCCT >>> GEII power

                      [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #12

                      toxcct wrote:

                      i can't see any difference

                      Because the OP has been modified.


                      "The largest fire starts but with the smallest spark." - David Crow

                      "Judge not by the eye but by the heart." - Native American Proverb

                      T 1 Reply Last reply
                      0
                      • C capricious_001

                        lol nono, the path directory is correct. I just forgot the extra backslash in this example. I tested it. having lszLogFile = "C:\\TeSt\\TeSt.txt"; works rather than having all the characters as lower case. So really the question is how do i retreive the case sensitive file path of that file -- modified at 13:09 Monday 19th June, 2006 I wrote that piece of code in my original post on the fly. I hate copying and pasting my code because its just too much too read.

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #13

                        capricious_001 wrote:

                        I hate copying and pasting my code because its just too much too read.

                        But copy/paste is the preferred method as needless posts can be avoided. You only need to paste the relevant snippets, not an entire program.


                        "The largest fire starts but with the smallest spark." - David Crow

                        "Judge not by the eye but by the heart." - Native American Proverb

                        1 Reply Last reply
                        0
                        • C capricious_001

                          Hi there, I am trying to use CreateFile to open up a file handle however in some instances it doesnt work. Is there a way to convert a file location string into its exact case-sensitive string? For example.

                          lszLogFile = "C:\\TeSt\\TeSt.txt";

                          HANDLE hLogFile = NULL;
                          hLogFile = CreateFile(lszLogFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

                          lszLogFile is the actual parameter that works with create file and a handle is created, however if

                          lszLogFile = "C:\\test\\test.txt";

                          Then a handle will not be created. Is there a way to find out what the actual Directory string is? Thanks guys, Robbie -- modified at 13:10 Monday 19th June, 2006 Added the extra backslashes, and no that wasnt the problem.

                          M Offline
                          M Offline
                          Michael Dunn
                          wrote on last edited by
                          #14

                          Windows file systems are not case-sensitive. If C:\test\test.txt is failing, it's due to something else, not the case of the letters. Check the value of GetLastError()

                          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer

                          1 Reply Last reply
                          0
                          • D David Crow

                            toxcct wrote:

                            i can't see any difference

                            Because the OP has been modified.


                            "The largest fire starts but with the smallest spark." - David Crow

                            "Judge not by the eye but by the heart." - Native American Proverb

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

                            DavidCrow wrote:

                            toxcct wrote: i can't see any difference Because the OP has been modified.

                            nope David, because i was joking... check the joke icon ;P;)


                            TOXCCT >>> GEII power

                            [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                            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