_readdir() translates some non-ASCII characters in file names

Started by RobertSteed, Today at 11:19:49 AM

Previous topic - Next topic

RobertSteed

Dear forum,
My code includes the following:
#include <dirent.h>
#include <locale.h>
...
setlocale(LC_ALL, "");
...
_DIR *dir;
struct _dirent *dirent;
dir = _opendir(path); // Open the folder
...
dirent = _readdir(dir); // Read first entry in folder // Read first entry in folder
if (dirent == NULL)
{ perror(path);
return 1;
}
while (dirent != NULL) // While not at end of folder
{
printf("dirent->d_name = %s\n", dirent->d_name);
...

Which results in
dirent->d_name = Art of Beksinski 1978 (MHS) (2).jpgLater code tries to open the files found:
FILE *fh = fopen(fn, "rb");which of course results in an error message:
Couldn't open test data\Art of Beksinski 1978 (MHS) (2).jpg: No such file or directoryThe actual filename is "Art of Beksiński 1978 (MHS) (2).jpg" with a diacritic on the "n". _readdir() worked as expected for "00tést.jpg" which has a diacritic on the "e".
So how can I get _opendir to return all non-ASCII file names as they are, without translating some characters?

TimoVJL

Function fopen might be a problem too, as it works with ANSI filenames.
I did some tests, even i don't like those functions, as i rather use Win32 API.
May the source be with you

John Z

Hi,

Well first I've never used these functions so a grain of salt with my comments.

Looking into the header there is no Unicode or wide character support for the functions.  So support will be limited to code pages.  If using ANSI code page ( I guess for the UK ?) for example then the 233 é  exists and can be shown.  However the ANSI code page does not include an n with diacritic in fact the only n is 241 ñ, so the closest substitution is made.

So try a different code page?  I was going to suggest trying to get the 8.3 filename but it seems the same issue would hinder that too.

John Z

For example codepage 852  E4 is n with diacritic