Ryan Davis
6/5/2008 6:14:00 PM
On Jun 5, 2008, at 04:43 , Onur Gungor wrote:
> Peter Smith wrote:
>> i have a question. I have a working script, that scans some txt
>> files in a directory ,reads the lines and gives a few of that lines
>> out in new
>> files. But now, i wanted to scan the full subdirectorys for txt
>> files. And copy some lines out of that files. The files are in
>> different directorys belonging to the same subdirectory.
>
> try this:
> Dir['./**/*.txt']
well... you have to deal with the top level dir as well:
Dir['./**/*.txt'] + Dir['*.txt']
that's always bugged me about "**".
You can also use find for more flexibility:
require 'find'
txt = []
Find.find(".") do |path|
Find.prune if File.basename(path)[0] == ?.
txt << path if path =~ /txt$/
end