[ruby-it] Moving all files in a folder to another hard drive
SpringFlowers AutumnMoon
summercoolness a gmail.com
Mer 27 Ago 2008 08:10:59 CEST
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
}
--
Posted via http://www.ruby-forum.com/.
Maggiori informazioni sulla lista
Ml