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