Hey I'm trying to move multiple files from one folder to another. In the FileUtils line I am trying to search through all of the 4 character folders in the destination folder and then paste the file in the folder with the same base name as the file.
#!/usr/bin/env ruby require 'fileutils' my_dir = Dir["C:/Documents and Settings/user/Desktop/originalfiles/*.doc"] my_dir.each do |filename| FileUtils.cp(filename, "C:/Documents and Settings/user/Desktop/destinationfolder/****/" + File.basename(filename, ".doc")) end
You don't need fileutils or a systemcall, just rename the file to the new location. File rename won't work across partitions, and throws the error "Invalid cross-device link". FileUtils is a better choice in those cases, but for a simple move in the same partition, rename works.
YES it's possible, the only concern that you have to watch for is that the CopyTo path should be the full path, not the relative one (ex: c:\websites\myOtherFolder). this way, you can successfully copy/move the file from your ASP.NET code.
copy() function as shown in the following R syntax. Within the file. copy function, we have to specify the directory path and file names of the first folder from which we want to copy the files, as well as the directory path and file names of the second folder to which we want to copy the files.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With