Pelles C forum

C language => Expert questions => Topic started by: RobertSteed on August 23, 2026, 11:19:49 AM

Title: _readdir() translates some non-ASCII characters in file names
Post by: RobertSteed on August 23, 2026, 11:19:49 AM
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?
Title: Re: _readdir() translates some non-ASCII characters in file names
Post by: TimoVJL on August 23, 2026, 02:08:45 PM
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.