| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#11
| |||
| |||
| On Tue, 2008-08-26 at 01:07 +0900, Dave Bass wrote: > Presumably you're using the NTFS filesystem? There's some information on > it here: > > http://en.wikipedia.org/wiki/NTFS > > Since the filesystem has a closed specification (thank you Microsoft), > it may be that the Ruby developers have been unable to work out exactly > how it works with filenames that contain Unicode characters. Yes ... my advice is to "shell out" to Windows or call native C libraries, rather than trying to "reverse engineer" NTFS. > > > -- M. Edward (Ed) Borasky ruby-perspectives.blogspot.com "A mathematician is a machine for turning coffee into theorems." -- Alfréd Rényi via Paul Erdős |
|
#12
| |||
| |||
| Axel Etzold wrote: > require "cgi" > > files.each { |file| > p CGI.escape(file) > # and then move files > } > > That's not elegant, but it will produce names with only % and ASCII > letters. > > > How does rio behave under Windows (http://rio.rubyforge.org/) ? thanks for helping. the cgi actually prints out %3F which is the ASCII for "?" since maybe the byte printed by each byte is 69, so encoding with CGI method will give %3F I tried Rio. It actually bypass all files with international characters in it. So for example, if my directory has 10 files, and 3 of them with the filename containing international characters in them, then rio(basedir).files['*.*'] actually just return 7 files. -- Posted via http://www.ruby-forum.com/. |
|
#13
| |||
| |||
| 2008/8/24 SpringFlowers AutumnMoon <summercoolness@gmail.com>: > I have some code below to move all files in a folder to another hard > drive (which has 2TB of space). It runs well except that whenever a > filename has some international characters, then the line > > if File.file?(basedir + file) > > will fail. The file is printed as "Chart for ???????.xls" > > Does someone know how to solve this problem with Ruby being so powerful? > The program is running on Windows. (Vista or XP should both be ok). > > code: > ------------------------------------ > > require 'ftools' > > basedir = "c:/data/" > target = "w:/data/" > > Dir.chdir(basedir) > files = Dir.glob("*"); > > i = 1 > files.each { |file| > p i, file > if File.file?(basedir + file) > puts "Moving..." > File.move(basedir + file, target + file) > puts "Now sleeping..." > sleep(60) > end > i += 1 > } As a quick workaround, try this: require 'Win32API' FILE_ATTRIBUTE_DIRECTORY = 0x10 MoveFileW = Win32API.new('kernel32','MoveFileW','PP','I') GetFileAttributesW = Win32API.new('kernel32','GetFileAttributesW','P',' L') basedir = "c:/data/" target = "w:/data/" basedirw = basedir.gsub(/(.)/,"\\1\000") targetw = target.gsub(/(.)/,"\\1\000") Dir.chdir(basedir) files = `cmd /u /c dir /b `.split("\r\000\n\000") i = 1 files.each {|file| p i, file if GetFileAttributesW.call(basedir + file) != FILE_ATTRIBUTE_DIRECTORY puts "Moving ..." MoveFileW.call(basedirw+file+"\000",targetw+file+" \000") puts "Now sleeping..." end i += 1 } Regards, Park Heesob |
|
#14
| |||
| |||
| Heesob Park wrote: > 2008/8/24 SpringFlowers AutumnMoon <summercoolness@gmail.com>: >> >> >> } > As a quick workaround, try this: > > > require 'Win32API' > FILE_ATTRIBUTE_DIRECTORY = 0x10 > MoveFileW = Win32API.new('kernel32','MoveFileW','PP','I') > GetFileAttributesW = > Win32API.new('kernel32','GetFileAttributesW','P',' L') > > [...] Wow, it really works! You rock, Park! Looks like one key line here is the `cmd /u /c dir /b`, which is to get the filenames in unicode characters. After that, I tried p "good" if File.file?(file) in Ruby 1.8.6 and 1.9 and they both gave error that the filename contains null character. Hm, I wonder for people who use Ruby on Japanese Windows XP/Vista, or European version of Windows, how do they deal with getting filenames that has non-English characters? Do we want to have a small speed competition and see which country can provide the first solution using fairly standard Ruby? (without resorting to win32api)? Thanks a lot, Park! -- Posted via http://www.ruby-forum.com/. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.