-
August 2nd, 2009, 07:53 AM
#1
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.
-
August 2nd, 2009, 10:58 AM
#2
Re: Rename a unicode file
Sounds like a corrupt hard drive. I saw the same thing last week. All files in Program Files were ??????.??
-
August 4th, 2009, 07:20 AM
#3
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.
-
August 4th, 2009, 07:46 AM
#4
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?
-
August 4th, 2009, 08:15 AM
#5
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"
-
August 5th, 2009, 10:51 AM
#6
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)
-
August 5th, 2009, 11:31 AM
#7
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.
-
August 5th, 2009, 05:21 PM
#8
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
-
August 5th, 2009, 05:38 PM
#9
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
-
August 5th, 2009, 08:56 PM
#10
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
-
August 7th, 2009, 11:05 AM
#11
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.
-
August 9th, 2009, 07:55 AM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|