tronkko / dirent

C/C++ library for retrieving information on files and directories

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

opendir method can not open folder named by chinese

XikangSun opened this issue · comments

Hello, tronkko.
Thank you for your unselfish work. I tested your programs and find one problem. That opendir method can not open folders named by chinese. It seems chinese word is wide charactor itself. Can you help to solve this problem? To make it work well both in English and Chinese.

Best Regards.

Xikang

In your own programs, you could use _wopendir and similar functions. They operate on wide-character set and should work correctly irrespective of the system locale.

The problem with the example programs is that they use single-character version of dirent functions and these functions expect to receive the file names encoded in the character set Windows is configured to use. If Windows is configured to use latin1 or a similar single-byte character set, then file names having UTF-16 characters may become unreachable. This may be fixed by changing the system locale to UTF-8.

Thank you for your reply. But what should I do, when a string contains both Chinese and English charactors?
As a chinese charactor uses two bytes, and a english charator uses one bytes?

Hello , tronkko.
I fixed this issue, by setlocale. I think other country people may solve this problem, use this method.
Thank you very much.

#include <locale.h>

#if defined(_MSC_VER) && _MSC_VER >= 1400

	/* Microsoft Visual Studio 2005 or later */
	setlocale(LC_ALL,"chs");
	error = mbstowcs_s(pReturnValue, wcstr, sizeInWords, mbstr, count);