[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Recursive directory listing

seebs

5/18/2007 9:26:00 AM

In message <464D6FED.8030701@exilregeringen.se>, Jesper writes:
>I read somewhere (online, not in the Pickaxe which is out of reach at
>the moment), that "**/*.mp3" would search through all levels, looking
>for *.mp3 files... but that doesn't seem to be the case. My (pig-ugly)
>code at the moment looks something like:

It seems to me that this might be a feature of some *shells*, but
I've never seen it in Ruby.

>It gets very bloated when I want to find many different extensions many
>(all) levels down, surely there is some better way to do this? Any hints
>of references would be appreciated.

You will almost certainly have to actually write the code to list, look
for directories, change to them, and recurse.

-s

1 Answer

Robert Klemme

5/18/2007 10:00:00 AM

0

On 18.05.2007 11:26, Peter Seebach wrote:
> In message <464D6FED.8030701@exilregeringen.se>, Jesper writes:
>> I read somewhere (online, not in the Pickaxe which is out of reach at
>> the moment), that "**/*.mp3" would search through all levels, looking
>> for *.mp3 files... but that doesn't seem to be the case. My (pig-ugly)
>> code at the moment looks something like:
>
> It seems to me that this might be a feature of some *shells*, but
> I've never seen it in Ruby.

Then you've never used Dir[] or Dir.glob().

11:51:25 [~]: ruby -e 'puts Dir["/usr/lib/**/*.{h,so}"]'
/usr/lib/ruby/1.8/i386-cygwin/config.h
/usr/lib/ruby/1.8/i386-cygwin/defines.h
/usr/lib/ruby/1.8/i386-cygwin/dl.h
/usr/lib/ruby/1.8/i386-cygwin/dlconfig.h
/usr/lib/ruby/1.8/i386-cygwin/dln.h
/usr/lib/ruby/1.8/i386-cygwin/env.h
/usr/lib/ruby/1.8/i386-cygwin/intern.h
/usr/lib/ruby/1.8/i386-cygwin/missing.h
/usr/lib/ruby/1.8/i386-cygwin/node.h
/usr/lib/ruby/1.8/i386-cygwin/re.h
/usr/lib/ruby/1.8/i386-cygwin/regex.h
/usr/lib/ruby/1.8/i386-cygwin/ruby.h
/usr/lib/ruby/1.8/i386-cygwin/rubyio.h
/usr/lib/ruby/1.8/i386-cygwin/rubysig.h
/usr/lib/ruby/1.8/i386-cygwin/st.h
/usr/lib/ruby/1.8/i386-cygwin/util.h
/usr/lib/ruby/1.8/i386-cygwin/version.h
/usr/lib/engines/lib4758cca.so
/usr/lib/engines/libaep.so
/usr/lib/engines/libatalla.so
/usr/lib/engines/libchil.so
/usr/lib/engines/libcswift.so
/usr/lib/engines/libgmp.so
/usr/lib/engines/libnuron.so
/usr/lib/engines/libsureware.so
/usr/lib/engines/libubsec.so
/usr/lib/ruby/1.8/i386-cygwin/bigdecimal.so
/usr/lib/ruby/1.8/i386-cygwin/curses.so
/usr/lib/ruby/1.8/i386-cygwin/dbm.so
/usr/lib/ruby/1.8/i386-cygwin/digest.so
/usr/lib/ruby/1.8/i386-cygwin/dl.so
/usr/lib/ruby/1.8/i386-cygwin/enumerator.so
/usr/lib/ruby/1.8/i386-cygwin/etc.so
/usr/lib/ruby/1.8/i386-cygwin/fcntl.so
/usr/lib/ruby/1.8/i386-cygwin/gdbm.so
/usr/lib/ruby/1.8/i386-cygwin/iconv.so
/usr/lib/ruby/1.8/i386-cygwin/nkf.so
/usr/lib/ruby/1.8/i386-cygwin/openssl.so
/usr/lib/ruby/1.8/i386-cygwin/pty.so
/usr/lib/ruby/1.8/i386-cygwin/readline.so
/usr/lib/ruby/1.8/i386-cygwin/sdbm.so
/usr/lib/ruby/1.8/i386-cygwin/socket.so
/usr/lib/ruby/1.8/i386-cygwin/stringio.so
/usr/lib/ruby/1.8/i386-cygwin/strscan.so
/usr/lib/ruby/1.8/i386-cygwin/syck.so
/usr/lib/ruby/1.8/i386-cygwin/syslog.so
/usr/lib/ruby/1.8/i386-cygwin/tcltklib.so
/usr/lib/ruby/1.8/i386-cygwin/tkutil.so
/usr/lib/ruby/1.8/i386-cygwin/Win32API.so
/usr/lib/ruby/1.8/i386-cygwin/win32ole.so
/usr/lib/ruby/1.8/i386-cygwin/zlib.so
/usr/lib/ruby/1.8/i386-cygwin/digest/md5.so
/usr/lib/ruby/1.8/i386-cygwin/digest/rmd160.so
/usr/lib/ruby/1.8/i386-cygwin/digest/sha1.so
/usr/lib/ruby/1.8/i386-cygwin/digest/sha2.so
/usr/lib/ruby/1.8/i386-cygwin/racc/cparse.so
11:51:34 [~]:

>> It gets very bloated when I want to find many different extensions many
>> (all) levels down, surely there is some better way to do this? Any hints
>> of references would be appreciated.
>
> You will almost certainly have to actually write the code to list, look
> for directories, change to them, and recurse.

Yep, guess so. Documentation of Net::FTP does not mention path globbing
like Dir[] does.

Kind regards

robert