[Win32utils-devel] win32-dir, unicode
Heesob Park
phasis at gmail.com
Fri May 26 02:16:26 EDT 2006
Hi,
2006/5/26, Daniel Berger <djberg96 at gmail.com>:> Hi,>> I've got a preliminary version of the pure Ruby version of win32-dir in> CVS. However, I was hoping to work out the Unicode issue. Run this:>> from = "C:\\test"> to = "Ελλάσ"> Dir.mkdir(from) unless File.exists?(from)> Dir.create_junction(to, from)>> It works, but my explorer (and dos) window shows the name garbled. I> don't think it's a font encoding issue within Explorer, since I can> create a folder called "Ελλάσ" manually within Explorer and it looks> correct.>You can check whether the folder name is whether unicode or ansi ?
How about some modification of create_function method like this:
def self.create_junction(to, from,unicode=false) # Normalize the paths to.tr!('/', "\\") from.tr!('/', "\\")
to_path = 0.chr * 260 from_path = 0.chr * 260 buf_target = 0.chr * 260
if GetFullPathName(from, from_path.size, from_path, 0) == 0 raise StandardError, 'GetFullPathName() failed: ' + get_last_error endif unicode if GetFullPathNameW(to, to_path.size, to_path, 0) == 0 raise StandardError, 'GetFullPathName() failed: ' + get_last_error endelse if GetFullPathName(to, to_path.size, to_path, 0) == 0 raise StandardError, 'GetFullPathName() failed: ' + get_last_error endend to_path = to_path.split("\0\0").first from_path = from_path.split(0.chr).first
# You can create a junction to a directory that already exists, so # long as it's empty.
if unicode rv = CreateDirectoryW(to_path, 0) if rv == 0 && rv != ERROR_ALREADY_EXISTS raise StandardError, 'CreateDirectory() failed: ' + get_last_error end
handle = CreateFileW( to_path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0 )else rv = CreateDirectory(to_path, 0) if rv == 0 && rv != ERROR_ALREADY_EXISTS raise StandardError, 'CreateDirectory() failed: ' + get_last_error end
handle = CreateFile( to_path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0 )end...end
And call like this:from = "C:\\test"Dir.mkdir(from) unless File.exists?(from)#unicode folder nameto = "\x95\x03\xBB\x03\xBB\x03\xAC\x03\xC3\x03\0\0" # "Ελλάσ"Dir.create_junction(to, from,true)#ansi folder nameto = "ansi"Dir.create_junction(to, from,false)
Regards,
Park Heesob
More information about the win32utils-devel
mailing list