question about .gsub

J

Jochen Kaechelin

line = `tree /Users/aragon/Documents -d`
line.each { |l|
l = l.gsub(/\|/,' ')
l = l.gsub(/\-/,' ')
l = l.gsub(/\`/,' ')

line = l
puts line
}


I use the gsub commands because the tree command produces the
following output:

|-- DUMMY
|-- lesen.rb
|-- test.txt
|-- test1.rb
|-- test2.rb
`-- tree.rb

Is there a way to reduce the code?
 
J

Jochen Kaechelin

Paul said:
Seems a shame to strip off all that tree-like formatting and characters,
created with so much effort.

I want them to be store in a mysql-database.
Is there a way to reduce the code?

puts l.gsub!(%r{[`\-\|]},' '}

Not tested.

By the way, what are you trying to create? There are better ways to produce
a tree display within Ruby itself.

I want to build a dropdown-menu so the admin ca select the
homedirectory of an ftpuser.

Could you please point me to a better solution?

Thanx
 
J

Jochen Kaechelin

Paul said:
Jochen Kaechelin wrote:

/ ...


By "them" do you mean individual file names, or the entire tree structure?
If the former, which parts of the file information do you need?

I need the complete path - no filenames (dirname, basename?).
I need no additional file information - only the complete path.
I ask because Ruby has many terrific ways to extract file information,
without having to make Windows system calls.

/ ...


Only with better information. How are the FTP users organized? What kind of
drop-down menu, using what GUI library?

All FTP users a stored in a mysql database, uid, gid, MaxMB,
DownloadBandwith .... The admin tool runs under apache and Ruby on
Rails.
 
J

Jochen Kaechelin

I found a script which solves my problem:


#!/usr/local/bin/ruby

require 'find'

dirs = ["/Users/aragon/Sites"]
excludes = []
for dir in dirs
Find.find(dir) do |path|
if FileTest.directory?(path)
if excludes.include?(File.basename(path))
Find.prune # Don't look any further into this directory.
else
next
end
else
puts path
end
end
end


Thanx.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top