Copying a file from one directory to another with Ruby

Something like this should work.

my_dir = Dir["C:/Documents and Settings/user/Desktop/originalfiles/*.doc"]
my_dir.each do |filename|
  name = File.basename('filename', '.doc')[0,4]
  dest_folder = "C:/Documents and Settings/user/Desktop/destinationfolder/#{name}/"
  FileUtils.cp(filename, dest_folder)
end

You have to actually specify the destination folder, I don’t think you can use wildcards.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)