From: Daniel Harple Date: 2006-07-24T13:17:14+09:00 Subject: Re: checking for directory (noob mistake?) On Jul 23, 2006, at 11:55 PM, bilal33@gmail.com wrote: > Dir.foreach("c:/") do |temp| > p "#{temp} #{File.expand_path temp}" > p File.directory? "#{File.expand_path temp}" > end > > basically, I need to detect which items under my C drive (or any other > folder for that matter) are directories. With the code above, I can't > seem to get this to work. I added the expand path call so that I know > that I am getting the folders correctly. > > Am I missing something really obvious here? Why can't I differentiate > between a file and a directory? Dir::entries (which Dir::foreach uses) just returns a list of files/ directories in the specified path, it does not return the path to them. You want Dir::glob: Dir.glob("/*") do |dir| puts "#{dir}: directory? #{File.directory?(dir)}" end -- Daniel