Need advice for parsing directories .ftp

Hi, Im currently working on a script that logs into an ftp server and
manipulates files by type. The problem I’ve run into is how can I
track/manipulate an arbitrary number of sub directories while tracking
the location of every parent dir. I can gather a list of
subdirectories of any current directory but i need an acurate tracking
to make sure every directory is searched. Should I use some sort of
stack counter or recursive function?

Aaron.

how can I track/manipulate an arbitrary number of sub directories
while tracking the location of every parent dir. I can gather a list of
subdirectories of any current directory but i need an acurate tracking
to make sure every directory is searched. Should I use some sort of
stack counter or recursive function?

I’ve always liked recursion. I just threw this together. Forgive me if
it doesn’t work perfectly. It’s a five minute throw together…

doesn’t handle dotfiles…

def drecurse(dirname)
Dir.open(dirname) do |dir|
dir.each do |file|
if test(?d, “#{dirname}/#{file}”)
next if file =~ /^./
puts “dir - #{dirname}/#{file}”
drecurse(“#{dirname}/#{file}”)
else
# Do something with file
end
end
end
end

drecurse(“.”)

···

Travis Whitton whitton@atlantic.net

Thank you very much! Thats an excellent example of what I was trying
to accomplish. Much more elegant that what I was going to do! Thanks
again!
Aaron.

···

I’ve always liked recursion. I just threw this together. Forgive me if
it doesn’t work perfectly. It’s a five minute throw together…

doesn’t handle dotfiles…

def drecurse(dirname)
Dir.open(dirname) do |dir|
dir.each do |file|
if test(?d, “#{dirname}/#{file}”)
next if file =~ /^./
puts “dir - #{dirname}/#{file}”
drecurse(“#{dirname}/#{file}”)
else
# Do something with file
end
end
end
end

drecurse(“.”)

Hi –

···

On Fri, 13 Dec 2002, Travis Whitton wrote:

how can I track/manipulate an arbitrary number of sub directories
while tracking the location of every parent dir. I can gather a list of
subdirectories of any current directory but i need an acurate tracking
to make sure every directory is searched. Should I use some sort of
stack counter or recursive function?

I’ve always liked recursion. I just threw this together. Forgive me if
it doesn’t work perfectly. It’s a five minute throw together…

doesn’t handle dotfiles…

def drecurse(dirname)
Dir.open(dirname) do |dir|
dir.each do |file|
if test(?d, “#{dirname}/#{file}”)
next if file =~ /^./
puts “dir - #{dirname}/#{file}”
drecurse(“#{dirname}/#{file}”)
else
# Do something with file
end
end
end
end

drecurse(“.”)

Could you use File::Find?

require ‘find’
File::Find.find do |file|
# tests
end

David


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

The code snippet that Travis sent was exactly what i was trying to do.
the problem i had visioning was keeping track of an arbitrary number
of directorys and sub directories using the limited set of commands
that ftp allows. My script needed to go through an entire ftp site and
back up files of a specific type and keep the same dir structure
offline.

···

Hi –

On Fri, 13 Dec 2002, Travis Whitton wrote:

how can I track/manipulate an arbitrary number of sub directories
while tracking the location of every parent dir. I can gather a list of
subdirectories of any current directory but i need an acurate tracking
to make sure every directory is searched. Should I use some sort of
stack counter or recursive function?

I’ve always liked recursion. I just threw this together. Forgive me if
it doesn’t work perfectly. It’s a five minute throw together…

doesn’t handle dotfiles…

def drecurse(dirname)
Dir.open(dirname) do |dir|
dir.each do |file|
if test(?d, “#{dirname}/#{file}”)
next if file =~ /^./
puts “dir - #{dirname}/#{file}”
drecurse(“#{dirname}/#{file}”)
else
# Do something with file
end
end
end
end

drecurse(“.”)

Could you use File::Find?

require ‘find’
File::Find.find do |file|

tests

end

David