1
我想列出具有非英文字符文件的文件夹。 下面的函数接受一个参数,比如C:\
并列出里面的文件。但不是100%正确。对于土耳其字符,它会打印一些符号,即使我使用了wchar_t
类型。
void listFolder(const wchar_t* path){
DIR *dir;
struct _wdirent *dp;
wchar_t * file_name;
wchar_t fullpath[MAX_PATH];
dir = _wopendir(path);
while ((dp=_wreaddir(dir)) != NULL) {
//printf("[i]debug: \t%s\n", dp->d_name);
if (!wcscmp(dp->d_name, L".") || !wcscmp(dp->d_name, L"..")){
// do nothing
}
else {
file_name = dp->d_name; // use it
wprintf(L"[*]file_name: \t\"%ls\"\n",file_name);
}
}
_wclosedir(dir);
}
我目前使用的是Windows 7 64位系统与代码块16.01
奇怪的部分是,Ubuntu的16.04下相同功能的工作完全正常使用的代码块。
这是正常行为对于Windows控制台,看到http://stackoverflow.com/questions/15827607/writeconsolew-wprintf-and-unicode您需要将代码页更改为一个支持你的字符想要打印 – Richard