How to open file with single quote in its name?
-
Under Windows, I try to open file which name contains apostrophe or some letters in language other than English. In these cases
fopen
orCreateFile
(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. -
Under Windows, I try to open file which name contains apostrophe or some letters in language other than English. In these cases
fopen
orCreateFile
(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. -
I just tried a file named "foo'baÇÉØr.txt" and it opened fine. You must have some other issue with yours.
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.
-
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.
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.
-
I just tried a file named "foo'baÇÉØr.txt" and it opened fine. You must have some other issue with yours.
-
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"
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
, andgt
). -
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"
-
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
, andgt
).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.