From: William James Date: 2006-02-18T15:58:31+09:00 Subject: Re: Removing files in directtories John Maclean wrote: > Almost there... I've included line 7 as I'd like to be able to remove > files from a directory using code blocks. Commented it out for now > until I can work out how it's done. Suggestions appreciated. > > #!/usr/bin/ruby -w > def back_up > backdir = ENV["HOME"] + "/foo/" > puts "about to backup some files and tar them into ~/foo" > puts "listing data in ~/foo" > Dir.foreach(backdir) {|file_names| > # File.delete("#{backdir}" + file_names) > puts File.directory? > file_names } > end > back_up > > -- > John Maclean > MSc (DIC) > 07739 171 531 def back_up backdir = ENV["HOME"] + "/foo/" puts "about to backup some files and tar them into ~/foo" puts "listing data in ~/foo" Dir.foreach(backdir) { |name| name = File.join( backdir, name ) if File.file?( name ) yield name end } end back_up { |file_name| puts file_name }