Question: ruby vs. ksh


(David Douthitt) #1

hal9000@hypermetrics.com 7/2/02 12:28PM >>>
recurse(dir) do |item|
File.delete(item)
end

Find.find is very similar, though it first visits directories and then
their content (preventing to delete directories), and does not change
the current dir.

find #{start} ! -type d.each { |file|
File.delete(file)
}

ksh again :open_mouth:

…Hal Fulton said:

It might also be good to have an iterator that only
visited directories. But I haven’t thought that through.

find #{start} -type d.each { |dir|

}

ksh yet again… :open_mouth:

···

----- Original Message -----
From: “Massimiliano Mirra” list@NOSPAMchromatic-harp.com.web-hosting.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, July 02, 2002 12:19 PM
Subject: Re: Question: ruby vs. ksh


(SER) #2

David Douthitt wrote:

find #{start} ! -type d.each { |file|
File.delete(file)
}

ksh again :open_mouth:

Why not use ‘find’?

require 'find’
require 'ftools’
Find.find( start ) { |file|
File.delete(file) if File.file? file
}

find #{start} -type d.each { |dir|

}

ksh yet again… :open_mouth:

Why not use ‘find’? :wink:

Actually, this is a bit more complicated, because Ruby doesn’t have a
recursive unlink:

require 'find’
require 'ftools’
dirs = []
Find.find( start ) do |file|
if File.file?(file) ; File.rm_f(file)
elsif File.directory?(file) ; dirs << file
end
dirs.sort{ |x,y| y.length <=> x.length }.each{ |d| Dir.delete d }

···

… “You need someone listening to you for it to be an actual
<|> conversation.”
/|\
/|