listing folder contents

E

eoghan

Hi
Im listing the contents of a folder using this:
Find.find('/Volumes/MYBOOK/stuff/') do |f| p f end
This is fine, but im seeing hidden files are with ._ prefix.
Is there any easy way to exclude this?
The folder contains sub folders alphabetised, as in a, b, c, d etc
another thing; when i print this i get:
"/Volumes/MYBOOK/stuff/a/file.stuff"
how could i just print
/a/file.stuff?
Thanks!
Eoghan
 
S

Sandor Szücs

Hi Eoghan,

Im listing the contents of a folder using this:
Find.find('/Volumes/MYBOOK/stuff/') do |f| p f end
This is fine, but im seeing hidden files are with ._ prefix.
Is there any easy way to exclude this?

If you just don't want '._' prefix then match the File.basename with
regex and
do an if.

Find.find('/Volumes/MYBOOK/stuff/') do |f|
puts(f) if not File.basename(f).match(/^\._/)
end

Find.find(`pwd`.chomp) do |f|
puts(f) if not f.match(/^\._/)
end


If you don't want to see all hidden files you can use Rake::FileList
instead
of using Find.find.
irb> Rake::FileList['**/*']
=> ["bfs_listing.rb", "bla", "bla/bla", "bla/bla/bla", "bla/bla/bla/
bla",
"bla/bla/bla/bla/fasel2", "bla/fasel", "test1"]

Here my example dir tested with your find
irb> Find.find(".") do |f| p f end
"."
"./test1"
"./bla"
"./bla/fasel"
"./bla/bla"
"./bla/bla/bla"
"./bla/bla/bla/bla"
"./bla/bla/bla/bla/fasel2"
"./bla/bla/bla/bla/._nein"
"./bla/bla/bla/._nein"
"./bla/bla/._nein"
"./bla/._nein"
"./bfs_listing.rb"
"./.test"
"./._nein"
=> nil
The folder contains sub folders alphabetised, as in a, b, c, d etc
another thing; when i print this i get:
"/Volumes/MYBOOK/stuff/a/file.stuff"
how could i just print
/a/file.stuff?

The behaviour of Rake::FileList is that what I think you want, but
you can
implement your own tree traverse if you want.

hth. sz
--
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top