From: "Morris, Chris" Date: 2002-01-12T04:19:22+09:00 Subject: RE: File management routines? I don't know of such a collection, but I've got a delTree method I can contribute. By default does a complete recursive delete on a directory. Optional filename pattern to only delete certain file names. If you need fancier criteria, you can use a block to test each filename prior to deletion (I used this recently to only delete old files). It also has unit tests for it. Whole thing is BSD licensed here: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/scrapware/scrapware/clutil/ru by/ class Dir def Dir.empty?(dirname) Dir.entries(dirname).length == 2 end end module ClUtilFile ALL_FILES = '*' def ClUtilFile.delTree(rootDirName, pattern=ALL_FILES) if (rootDirName == '/') or (rootDirName.empty?) raise 'Cannot delete root or empty?' end if !File.exists?(rootDirName) raise 'rootDirName does not exist' end # puts all sub-dirs and filenames in array. # Sub-dirs will be breadth first search. dirsAndFiles = Dir["#{rootDirName}/**/" + pattern] # delete all files first dirsAndFiles.each do | dirOrFileName | if FileTest.file?(dirOrFileName) if block_given? File.delete(dirOrFileName) if yield dirOrFileName else File.delete(dirOrFileName) end end end # go through array backward to delete dirs in proper order dirsAndFiles.reverse_each do | dirOrFileName | if FileTest.directory?(dirOrFileName) Dir.delete(dirOrFileName) if Dir.empty?(dirOrFileName) end end Dir.delete(rootDirName) if Dir.empty?(rootDirName) end end > -----Original Message----- > From: Massimiliano Mirra [mailto:list@chromatic-harp.com] > Sent: Friday, January 11, 2002 9:25 AM > To: ruby-talk@ruby-lang.org > Subject: File management routines? > > > Is there any collection of file management routines, such as recursive > copy/deletion, forced removal etc., that uses Ruby's File class only > and no platform specific commands? I had a look at the RAA but wasn't > able to find anything. > > Massimiliano >