From: Rob Biedenharn Date: 2007-09-28T00:35:17+09:00 Subject: Re: Recursing through directories On Sep 27, 2007, at 10:55 AM, Gabriel Dragffy wrote: > On 27 Sep 2007, at 14:14, Rob Biedenharn wrote: >> You're not providing a receiver for the gsub() method. Having >> said that, though, what it seems like you're trying to do is >> almost certainly a bad idea. It looks like you're prepared to >> move all files into the current directory. If that's not what you >> intended, then it's probably very good that you got an error. >> >> -Rob > > I'm sorry, you are so right. I really can't seem to get the hang of > this. You're correct in that it is moving all files in to the > current directory. How can I make it so it just renames them in > place, and which resource should I be ideally reading to understand > this better? > > Best regards > > Gabriel If you want to rename files having names that meet some pattern, why don't you start with print the names like this (files having "foo" somewhere in their name): Dir['**/*'].each {|f| puts f if f =~ /foo/ } but beware that Dir['**/*'] is going to plow through the directory structure and make an array (a big one) of all the file names before the block gets to see any of those names. Perhaps you'd get some better answers if you post what you're trying to accomplish, the attempt you've made (or what you think should work), and the actual results you see. Also, note that my example starts from the current directory (which was ~/ in my case). It's always better to get a script like yours working on a small bit of known data (and perhaps be non-destructive) before turning it loose on your entire disk. (In my case, it found many files that were throwaway "foo" files, but also many with "foot", "footnote", "food", and "footer" that were clearly not throwaway files.) -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com