From: Aldric Giacomoni <"aldric[remove]"@...> Date: 2008-12-17T05:07:28+09:00 Subject: Re: Walk through directory structure, look at first file, rename dir in consequence. Einar Magn�s Boson wrote: > > You only want the first file in every directory and every sub- > directory? is that it? > > With this setup: > /dir1/file1 > /dir1/dir11/file1 > /dir1/dir11/file2 > /dir1/dir12/file1 > /dir1/dir12/file2 > > you only want /dir1/file1, /dir1/dir11/file1 and dir1/dir12/file1, is > that correct? > > I guess you could do something like this: > > def getFilesInDirectory(dir) > dirs = [] > files = [] > Dir[File.join(dir, "*")].each do |f| > if File.directory?(f) then > dirs << f > elsif files.empty? > files = [f] > end > end > dirs.each do |dir| > files += getFilesInDirectory(dir) > end > files > end > > > einarmagnus > That does exactly what I need! What a cool solution.. Thank you! --Aldric