From: "Alex C." Date: 2012-07-04T03:34:38+09:00 Subject: Re: Copying Files Jan E. wrote in post #1067228: > Hi, > > Of course you don't have to write down every file separately. Then the > whole program wouldn't make sense, because you might as well copy the > files "by hand". > > I think the easiest way is to pass an array of the files to > FileUtils.copy. To get an array of all files inside a folder, use > "Dir[...]": > > http://ruby-doc.org/core-1.9.3/Dir.html#method-c-5B-5D > > You have to pass a certain path pattern, which is explained here: > > http://ruby-doc.org/core-1.9.3/Dir.html#method-c-glob > > > #---------------------------- > require 'fileutils' > > original_path, target_path = > 'C:/folder', 'C:/new' > FileUtils.copy Dir["#{original_path}/**/*.*"], target_path > #---------------------------- > > > By the way, be careful with backslashes in strings. Certain character > sequences like \n have a special meaning. So you should either escape > the backslashes (with another backslash) or replace them with normal > slashes. Hi, Thanks for the your help, it works great. I was using backslashes first and it didn't work until I changed them! Just another thing - can I add an exception to the files to be copied? for example, if I didn't want the files from a certain folder to be copied over the the target path? -- Posted via http://www.ruby-forum.com/.