CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2006
    Posts
    16

    Rename a unicode file

    I would like to rename some unicode files and folders. I do not know the language or point of origin. They are displayed with question marks ("??????.???") I want to be able to search them out and rename them so they can be moved to another location to be examined at a later date.

    I can capture the name and replace the characters in a variable but when I try to actually rename it on the disk, it errors off with an Error 52 (bad handle). Any suggestions? Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Rename a unicode file

    Sounds like a corrupt hard drive. I saw the same thing last week. All files in Program Files were ??????.??
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Mar 2006
    Posts
    16

    Re: Rename a unicode file

    Thannk you for the concern, however my drive is not corrupted. I am using VB 6 sp6 and need to rename these items, open and inspect them, and then delete them programatically.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Rename a unicode file

    the filename being all ?s does sound like the filename table has been corrupted for these files at least. Have you ran a check disk on it?

  5. #5
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Rename a unicode file

    You say you have captured the name to a variable...
    Have you captured the "????????.???" or have you captured the real unicode string somehow?
    How do you rename? Using Name... As... ?

    I could imagine a little loop using the filesystem object, walking through all the files, showing the names to ask for renaming.
    When you use the File object, renaming goes like this:
    File.Name = "NewName.xxx"
    This should overwrite the name, no matter what it is like.
    The ???? are only substitutes for the characters, the OS cannot display.
    So you can't Name "???????.???" As "NewName.xxx"

  6. #6
    Join Date
    Jul 2003
    Location
    Munich, Germany
    Posts
    51

    Re: Rename a unicode file

    You HD is not corrupted.
    VB6 cannot handle unicode correctly, e.g. if you have a filename with japanese characters, they will be displayed in a VB6 program as ?????

    You have to use a winapi function, I think it is CopyFileApiW to copy and to rename files:
    Declare Function CopyFileApiW Lib "kernel32" Alias "CopyFileW" ( _
    ByVal lpExistingFileName As Long, _
    ByVal lpNewFileName As Long, _
    ByVal bFailIfExists As Long) _
    As Long

    retval = CopyFileApiW(StrPtr(source), StrPtr(StrConv(Dest), 0)

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Rename a unicode file

    Normally, you cannot create a folder / file with a Question mark in it on any Windows OS. You get the Question marks because the file name is basically "unknown" / "uniterpretable" by Windows. So, neither Windows nor the Fie system is corrupt

    If you had known the origin of the file, I could've advised installing a language pack.

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Rename a unicode file

    Open with a Hex Editor to see what it is. It can't be valid. I'd guess that the file allocation table was written or failed
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

    Re: Rename a unicode file

    About all the '?' you're seeing - that's most likely because you don't have a font installed on your system that contains the glyphs for those Unicode characters.

    Run this on the command line: "cmd /U /C dir /S > files.txt"
    The resulting files.txt will be Unicode encoded. See if Word/WordPad/Notepad can render the glyphs. If not, search for some free CJK fonts that you can install then try again.

    gg

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Rename a unicode file

    Read this thread. I knew that I saw it before. Just found it.

    http://www.codeguru.com/forum/showthread.php?t=376680
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #11
    Join Date
    Mar 2006
    Posts
    16

    Re: Rename a unicode file

    To all, Thank you for your input.

    The file is not all "?", just a couple of the characters. I tried Name xxx As yyy and as one of you stated, it did not work. I will try the CopyFileW API and get back to you tomorrow. Have to get to work.

  12. #12
    Join Date
    Mar 2006
    Posts
    16

    Re: Rename a unicode file

    I read the article Dglienna recommended and it was some help. I finally accomplished what I needed by:

    1. Creating a unique file name in memory
    2. Using MoveFileW to rename the file or folder

    If the process failed, I used DeleteFileW to remove the questionable item.

    Consider this resolved and thank you for your input.

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