0

I use dirent.h library for fetching name of file. While most of them are correct, this one:

1Zdjęcie główne.JPG_38ba97e477158efb3563274f5bd39af7.jpg_cda6829b61253f64b44a5c7f15e00b45 - Copy.jpg

is read as

1ZDJCI~2.JPG

What can I do to prevent tilde substition behavior?

I use Windows 7, Visual Studio C++

path "./tiles/"

DIR *dir;
struct dirent *ent;
if ((dir = opendir(path.c_str())) != NULL) {
while ((ent = readdir(dir)) != NULL) {
if( strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0 ) { continue; }
string a(ent->d_name);

examples of "correct" (without tilde substitution) file names: "2012-07-29- 227.jpg_955c70788013c4979d5cad857b49d4d2.jpg_8551b27380326b183c17e3469ec97cd3.jpg" "2012-07-29-228.jpg_5b2281bbe1efd6bd7469c4a29114a210.jpg_ee6d3a75864e7e33b3d99c023c962dbf.jpg" "2012-08-31-842.jpg_93562fa908083e5a070467558bba2141.jpg_2e84cdbc1d5a5eb932a1373840119aa4.jpg"

Arko Jarko
  • 39
  • 2
  • 4
    ... have sane filenames? – sehe Nov 14 '13 at 20:58
  • How are you getting the file name? – shf301 Nov 14 '13 at 20:58
  • 'dirent.h` - it's a POSIX compat interface – sehe Nov 14 '13 at 20:58
  • List a few filenames that are "correct". – Jongware Nov 14 '13 at 21:05
  • The method you are using probably doesn't support Unicode and/or long paths. Maybe use UTF-16 Win32 functions and convert back to UTF-8 or whatever encoding you want to use? Unless you need something cross-platform. – user2802841 Nov 14 '13 at 21:08
  • I added code and examples of 'correct' file names i think it is POSIX interface. I haven't test windows functions for reading directory content so probably its good clue - use posix library on linux and windows on windows but maybe there is a cross-platform solution? – Arko Jarko Nov 14 '13 at 21:18

1 Answers1

1

You can call GetLongPathName to convert the short name (NAME~1.EXT) to it's long name.

Collin Dauphinee
  • 13,664
  • 1
  • 40
  • 71