From: gga Date: 2007-03-10T16:55:04+09:00 Subject: Re: Find.find --- returns directories/files backwards On 9 mar, 21:33, "Brad" wrote: > New user question: > > Am I missing something? How do you do get it to write out the > directories in alphabetical order? > You are probably using the wrong api. If you want to get a list of files/directories in a single directory, you should use: Dir.entries() or Dir.foreach() for more complex iterations. Find does a recursive search across multiple directories (and subdirectories). That being said, files are read and returned as your OS does. So it is up to you to sort them out into directories and not directories and to sort them out. You can usually do that with arrays. dir = Dir.pwd # # dirs and files sorted together # puts Dir.entries(dir).sort # # or... more complex... # dirs = [] files = [] Dir.foreach(dir) do |file| next if file =~ /^\..?$/ # ignore . and .. if File.directory?("#{dir}/#{file}") dirs << file else files << file end end dirs.sort! files.sort! puts dirs, "---", files # # or same, but simpler (more ruby-like) # all = Dir.entries(dir) - ['.', '..'] all.sort! dirs = all.select { |x| File.directory?("#{dir}/#{x}") } files = all - dirs puts dirs, "---", files