I am trying to list all files in current directory and sub-directories so I can know the size of a directory by calculating the size of all the files in it. But d_name returns a different file name, which I can't pass to fopen because it changes … in the filename to à. I don't know what other characters are changed. I believe getting the d_name in utf-8 can fix this.
Currently the part of the code is this:
DIR *dr;
struct dirent *d;
dr = opendir(foldername);
if (dr != NULL) {
for (d = readdir(dr); d != NULL; d = readdir(dr)) {
printf("d name: %s \n", d->d_name);
}
}
The actual filename is
Write For Us. Quick guide to explain how to send… _ by Domenico Nicoli _ Dev Genius.html
But d_name prints it as:
Write For Us. Quick guide to explain how to sendà _ by Domenico Nicoli _ Dev Genius.html
How can I fix this? I want to open, but it always gives a null pointer. Other files open neatly.
This seems to be a problem related to the difficult mapping between the filename encoding used by Windows and the UTF-8 encoding used by the Unix emulation for
opendirandreaddir.Can you try this debugging code so the encoding returned by
readdircan be further analysed: