Eventually you'll have to go down to using platform dependent code for accessing files which uses strings and not raw bytes so this is not likely to work. I suggest you try to detect file encoding based on the contents of the file path.
Eventually you'll have to go down to using platform dependent code for accessing files which uses strings and not raw bytes so this is not likely to work. I suggest you try to detect file encoding based on the contents of the file path.
I dont think I quite understand your suggestion about detecting encoding from filepath.
Do you mean I should read the directory with native os-calls to get the raw filename, guess the encoding based on that byte sequence and figure out som way of making that into a QString? If that suceeds i still can't use QFile to open, because it will use utf-8 when converting the QString filename to char *. So I would ... need to keep the filename as a QByteArray too so I can open the file with native os-calls and promote the FILE * to a QFile later. This is getting messy![]()
Found a better solution which means I can keep using the high-level classes instead of going down to os-specific code:
I browse directories with QDir/QFileInfo and let the filters include QDir::System. If an entry is neither A File nor a Directory, I make another QFileInfo on it using the fileName() from the first QFileInfo. I that works, the entry is most likely a socket/fifo/device node and will be ignored. But if it was not possible to make another QFileInfo it is probably because the filename was in the wrong encoding and has been stripped of some characters. The program will present a selection of failed filenames and suggest the user does e.g.
Qt Code:
convmv -f iso-8859-1 -t utf8 -r --notest *To copy to clipboard, switch view to plain text mode
to fix the filenames and then try again.
I mean to use statistics to guess what the encoding of the filename is and then to normalize names by converting them to Unicode.
Be aware that "down the well" QFile uses platform dependent means to access files and that was what I meant in my previous post.If that suceeds i still can't use QFile to open, because it will use utf-8 when converting the QString filename to char *. So I would ... need to keep the filename as a QByteArray too so I can open the file with native os-calls and promote the FILE * to a QFile later. This is getting messy![]()
Bookmarks