2013-11-14 46 views
0

我使用dirent.h庫來獲取文件名。雖然大部分都是正確的,這一個:如何獲得沒有代字號替換的真實文件名

1ZdjĂ「A「CIE GAAA€šÄ,Ĺ,wne.JPG_38ba97e477158efb3563274f5bd39af7.jpg_cda6829b61253f64b44a5c7f15e00b45 - Copy.jpg

讀作

1ZDJCI〜2。 JPG

我該怎麼做才能防止代替替代行爲?

我使用Windows 7時,Visual Studio C++

路徑 「./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); 

例子(沒有波浪線替換)文件名: 「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」

+4

...有合理的文件名? – sehe

+0

你是如何得到文件名? – shf301

+0

'dirent.h' - 這是一個POSIX兼容接口 – sehe

回答

1

您可以撥打GetLongPathName將短名稱(NAME〜1.EXT)轉換爲長名稱。

相關問題