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. ATL / WTL / STL
  4. How to open file with single quote in its name?

How to open file with single quote in its name?

Scheduled Pinned Locked Moved ATL / WTL / STL
helptutorialquestion
8 Posts 3 Posters 7 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.
  • L Offline
    L Offline
    liquid_
    wrote on last edited by
    #1

    Under Windows, I try to open file which name contains apostrophe or some letters in language other than English. In these cases fopen or CreateFile (from W32 library) fail to open it. How should I do that task? Wide character type, wfopen or defining UNICODE don't help. The functions say the file doesn't exist.

    L 1 Reply Last reply
    0
    • L liquid_

      Under Windows, I try to open file which name contains apostrophe or some letters in language other than English. In these cases fopen or CreateFile (from W32 library) fail to open it. How should I do that task? Wide character type, wfopen or defining UNICODE don't help. The functions say the file doesn't exist.

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

      I just tried a file named "foo'baÇÉØr.txt" and it opened fine. You must have some other issue with yours.

      L 2 Replies Last reply
      0
      • L Lost User

        I just tried a file named "foo'baÇÉØr.txt" and it opened fine. You must have some other issue with yours.

        L Offline
        L Offline
        liquid_
        wrote on last edited by
        #3

        Well, maybe. I read the name of file from another text file which is windows media player list (.wpl). E.g. I can't open file named "Baby,_I’m_Not_Sure_If_This_Is_Love.mp3" but this "05 - Cold Hearts.mp3" can be opened. There may be issue with encoding characters in the list but how it is possible that some files can be opened and others cannot from the same list. Of course, all files are playable by WMP.

        J 1 Reply Last reply
        0
        • L liquid_

          Well, maybe. I read the name of file from another text file which is windows media player list (.wpl). E.g. I can't open file named "Baby,_I’m_Not_Sure_If_This_Is_Love.mp3" but this "05 - Cold Hearts.mp3" can be opened. There may be issue with encoding characters in the list but how it is possible that some files can be opened and others cannot from the same list. Of course, all files are playable by WMP.

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          liquid_ wrote:

          I read the name of file from another text file which is windows media player list (.wpl)

          That is not really a text file but a XML file. Those use entities to encode special and non-ASCII characters which must be decoded when reading such files as text. See List of XML and HTML character entity references - Wikipedia, the free encyclopedia[^]. Alternatively use a XML parser.

          1 Reply Last reply
          0
          • L Lost User

            I just tried a file named "foo'baÇÉØr.txt" and it opened fine. You must have some other issue with yours.

            L Offline
            L Offline
            liquid_
            wrote on last edited by
            #5

            Additionally, here is what I see in debugger window as contents of the variable which contains the file name: "Baby,_I’m_Not_Sure_If_This_Is_Love.mp3"

            J L 2 Replies Last reply
            0
            • L liquid_

              Additionally, here is what I see in debugger window as contents of the variable which contains the file name: "Baby,_I’m_Not_Sure_If_This_Is_Love.mp3"

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #6

              That looks like UTF-8. XML files are usually UTF-8 encoded. So you must convert from UTF-8 to wide characters after reading the file content into memory (e.g. using MultiByteToWideChar function (Windows)[^]). Afterwards you must still check for entities as noted in my above post. Even when the WPL file does not use entities for non-ASCII characters it uses them for the reserved characters (quot, amp, apos, lt, and gt).

              L 1 Reply Last reply
              0
              • L liquid_

                Additionally, here is what I see in debugger window as contents of the variable which contains the file name: "Baby,_I’m_Not_Sure_If_This_Is_Love.mp3"

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

                I just created a file with that name and I was able to open it with another application. As I said before, I suspect the issue is something else. Are you sure that your path is correct when you try to open the file?

                1 Reply Last reply
                0
                • J Jochen Arndt

                  That looks like UTF-8. XML files are usually UTF-8 encoded. So you must convert from UTF-8 to wide characters after reading the file content into memory (e.g. using MultiByteToWideChar function (Windows)[^]). Afterwards you must still check for entities as noted in my above post. Even when the WPL file does not use entities for non-ASCII characters it uses them for the reserved characters (quot, amp, apos, lt, and gt).

                  L Offline
                  L Offline
                  liquid_
                  wrote on last edited by
                  #8

                  Definitely, it helped at least in half a problem. The rest lays in XML entities like &_amp_; (without underscore). I think I should treat them manually. Generally, mbstowcs won't help. I had to use win32 function where I can define more encoding standards.

                  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