CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: File path name has some chinese or other characters

  1. #1
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,844

    Re: File path name has some chinese or other characters

    You have to build your program as UNICODE.
    Victor Nijegorodov

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,399

    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?

  4. #4
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: File path name has some chinese or other characters

    Quote Originally Posted by VictorN View Post
    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.

  5. #5
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: File path name has some chinese or other characters

    Quote Originally Posted by Arjay View Post
    +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;
    			}
    	}

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,844

    Re: File path name has some chinese or other characters

    Quote Originally Posted by vcdebugger View Post
    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

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,399

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)