From: vasudevram Date: 2007-05-19T03:00:03+09:00 Subject: Re: Recursive directory listing On May 18, 2:20 pm, Jesper wrote: > Hello, > > I've made a small script that gets username + password from a form, and > uses them to log into an ftp-account, where it then search for specific > files (*.mp3, for example). > > 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: > > lines = ftp.nlst("*.mp3 **/*.mp3 ***/*.mp3 ****/*.mp3") > > 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. > > Regards, > > / J You could try to implement the file-tree walk function which is available in C libraries that come with the free C compilers like GCC; if I remember right, its called ftw(). Or an easier option could be to look at the source for the similar function/method of Python (I think there is one, since I was reading this in a Python book lately) and port it to Ruby. (I think the Python version even supports the prune option as in the UNIX find command). I don't think it should be too difficult and, though doing so would be an additional investment of time, its likely to stand you (and others, if you release the code for it) in good stead later as well, as walking a file tree is a common and generic need. If you're doing it, try to let it support blocks, so as to be more Rubyish (and useful) :-) Maybe I'll try to do it myself when I get some free time ... My 2c ... Vasudev Ram Dancing Bison Enterprises www.dancingbison.com