From: Michael Morin Date: 2008-08-22T01:35:04+09:00 Subject: Re: copy a folder and its contents Robert Klemme wrote: > 2008/8/21 aidy : >> Hi Lex, >> >> On Aug 21, 3:59 pm, Lex Williams wrote: >> >>> use cp_r >>> -- >>> Posted viahttp://www.ruby-forum.com/. >> Thanks, I had previously tried it and received this recursive >> exception >> >> No such file or directory - C:/rspec_reports/javascripts/test/ >> javascripts/test/javascripts/test/javascripts/test/javascripts/test/ >> javascripts/test/javascripts/test/javascripts/test/javascripts/test/ >> javascripts/test/javascripts/test/javascripts/test/javascripts/test/ >> javascripts > > This comes as no surprise because you are trying to copy a folder > hierarchy into a folder which is inside that hierarchy. In other > words: the recursion is in your copying. Are you sure this is what you > want? > > Kind regards > > robert > > It looks like he's just trying to make a backup of all the files in a directory. Try something like this. files = Dir.glob('*') FileUtils.mkdir 'backup' FileUtils.cp_r files, 'backup' This avoids cp_r trying to descend into the folder it's copying into. -- Michael Morin Guide to Ruby http://ruby.about.com/ Become an About.com Guide: beaguide.about.com About.com is part of the New York Times Company