CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2008
    Posts
    163

    Rename failed with file name had space, hyphen etc after unicode support.

    Hi,

    I intent to use this mechanism for rename the file because the file name consists Unicode characters
    I would like to know why the return value of "MoveFileExW" is false for file name consists 'space','hyphen' etc.(sometimes even without a Unicode character).for accepting 'space','hyphen' what type of conversion I would use [I.e.: Does the root cause of failure is due to CP_UTF8 type use]

    Please see the code

    Code:
       //! inputPath & final_inputPath consist source and destination file name and are std::string
       //! Both are in same directory F:\test_files\
       
       std::wstring unicode_input_original;
       int unicode_input_length_original = 0
       
       std::wstring unicode_input_final;
       int unicode_input_length_final = 0;
       
        unicode_input_length_original = MultiByteToWideChar(CP_UTF8,0,inputPath.data(),inputPath.length(),NULL,0);
        unicode_input_original.resize(unicode_input_length_original);
        MultiByteToWideChar(CP_UTF8,0,inputPath.data(),inputPath.length(),&unicode_input_original[0],unicode_input_original.length());
        const wchar_t *input_name_original = unicode_input_original.c_str();
    	
    	unicode_input_length_final = MultiByteToWideChar(CP_UTF8,0,final_inputPath.data(),final_inputPath.length(),NULL,0);
        unicode_input_final.resize(unicode_input_length_final);
        MultiByteToWideChar(CP_UTF8,0,final_inputPath.data(),final_inputPath.length(),&unicode_input_final[0],unicode_input_final.length());
        const wchar_t *input_name_final = unicode_input_final.c_str();
    	
    	bool ret = MoveFileExW(input_name_original,input_name_final,MOVEFILE_REPLACE_EXISTING);
    -Dave.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Rename failed with file name had space, hyphen etc after unicode support.

    I would like to know why the return value of "MoveFileExW" is false
    Where is your call to GetLastError? That is what you should call immediately after calling MoveFileExW if it returns 0.

    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Nov 2003
    Posts
    1,902

    Re: Rename failed with file name had space, hyphen etc after unicode support.

    Where does inputPath & final_inputPath come from and how do you know they are UTF8 encoded?

    Here's are some utility functions for doing the conversions: http://forums.codeguru.com/showthrea...31#post1790131

    You may want to change the return type to bool so that it's easy to detect conversion errors.

    gg

  4. #4
    Join Date
    Nov 2013
    Posts
    1

    Re: Rename failed with file name had space, hyphen etc after unicode support.

    Hi
    h r u
    i need your help pls if you have time

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Rename failed with file name had space, hyphen etc after unicode support.

    Quote Originally Posted by sarmad View Post
    Hi
    h r u
    i need your help pls if you have time
    You need a new keyboard. The one you have seems to be dropping letters.

    Once you get a keyboard that can type complete words, you may want to state what you'd like help with.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured