-
November 17th, 2020, 01:51 AM
#1
File path name has some chinese or other characters
Hi All,
I want to read a file which is present in some path which has some special characters as folder name as follows:
C:\Test\Input\新建文件夹\Text.txt
but problem now is with this special character in the path - not able to find proceed further.
The special characters "新建文件夹" are shown as "?????" if I check by putting break point.
Please let me know how to make this work.
Thanks
-
November 17th, 2020, 02:29 AM
#2
Re: File path name has some chinese or other characters
You have to build your program as UNICODE.
Victor Nijegorodov
-
November 17th, 2020, 02:47 AM
#3
Re: File path name has some chinese or other characters
+1 for what Victor said. Show us a snippet of code that opens the file.
Btw, did you know that most Win 32 APIs come in an ANSI version (GetVersionExA) and a UNICODE version (GetVersionExW)?
Did you know that Visual C++ will choose the correct API version for you based on whether you compile for ANSI or UNICODE?
Did you also know that the _T("") macro can save you a lot of grief when working with string literals in ANSI and UNICIDE apps?
-
November 17th, 2020, 04:28 AM
#4
Re: File path name has some chinese or other characters
Originally Posted by VictorN
You have to build your program as UNICODE.
Thanks for the response.
after changing the settings to UNICODE- it started to throw errors in my other part of the code as shown below:
: cannot convert from 'CString' to 'const char *'
Last edited by vcdebugger; November 17th, 2020 at 04:31 AM.
-
November 17th, 2020, 04:51 AM
#5
Re: File path name has some chinese or other characters
Originally Posted by Arjay
+1 for what Victor said. Show us a snippet of code that opens the file.
Btw, did you know that most Win 32 APIs come in an ANSI version (GetVersionExA) and a UNICODE version (GetVersionExW)?
Did you know that Visual C++ will choose the correct API version for you based on whether you compile for ANSI or UNICODE?
Did you also know that the _T("") macro can save you a lot of grief when working with string literals in ANSI and UNICIDE apps?
Thanks a lot for the response.
Since I am part time programmer once in 5-10 years, I dont remember these details.
Below is the code where the CString variable "m_edit_str_input_dump_file" contains the file path in the CEdit box.
FileExists() returns failure due to the chinese characters in this variable. Kindly let me know how to validate it, so it consider even special character folder also.
Code:
UpdateData(TRUE);
int inputDumpFile = CUtils::FileExists(m_edit_str_input_dump_file);
CString ext = CUtils::FileExtension(m_edit_str_input_dump_file);
if(inputDumpFile)
{
/*
if( (m_edit_str_input_dump_file.Find("EVENT.bin") != -1) || (m_edit_str_input_dump_file.Find("EVENT.BIN") != -1) || (m_edit_str_input_dump_file.Find("Event.bin") != -1) || (m_edit_str_input_dump_file.Find("event.bin") != -1) || (m_edit_str_input_dump_file.Find("Event.BIN") != -1) || (m_edit_str_input_dump_file.Find("event.BIN") != -1) )
{
EventBin = true;
iocMapExists = CUtils::FileExists(m_edit_str_event_log_ioc);
if(iocMapExists == 0)
{
AfxMessageBox("IO Correlation map file for converting Raw Event bin to formatted bin does not exists");
return;
}
}
else
if((m_edit_str_input_dump_file.Find("event") != -1) || (m_edit_str_input_dump_file.Find("Event") != -1) || (m_edit_str_input_dump_file.Find("EVENT") != -1))
{
EventBin = true;
}
*/
}
else
{
AfxMessageBox("Log input file does not exists \r\n Check if the path name is valid");
return;
}
}
-
November 17th, 2020, 05:51 AM
#6
Re: File path name has some chinese or other characters
Originally Posted by vcdebugger
Thanks for the response.
after changing the settings to UNICODE- it started to throw errors in my other part of the code as shown below:
: cannot convert from 'CString' to 'const char *'
- Use _T() macro (as Arjay already mentioned)
- Use TCHAR instead of char type
- Use LPTSTR instead of char* or LPSTR
- Use LPCTSTR instead of const char* or LPCSTR
See also https://docs.microsoft.com/en-us/cpp...?view=msvc-160
Victor Nijegorodov
-
November 17th, 2020, 08:03 AM
#7
Re: File path name has some chinese or other characters
As a start, replace all the hardcoded "my string" string literals with the _T("") macro.
For example, "EVENT.BIN" would become _T("EVENT.BIN").
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|