From: Geoff Date: 2006-08-05T02:15:07+09:00 Subject: Re: Dir.glob finding folders Just to follow up, I did try this and it worked. I also want to add that the reason I was trying to use Dir is because in searching for solutions to this I found reference to it being faster. I would still love to hear any feedback on how to optimize this or change the solution so that it would speed things up. Searching a 60gb hard drive this way takes a while. :) Anyway, my solution that eventually worked: require 'find' file = File.open("projects.txt", "w") print "Enter Drive Letter: " drive_letter = gets.chomp Find.find("#{drive_letter}:/") do |path| if FileTest.directory?(path) if path =~ /CFI-/ file << "#{path} \n" end end end Thanks! Geoff Suraj N. Kurapati wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Geoff wrote: > > I want to prompt to get the letter of the drive to search, > > then if the directory has the text "CFI-" in it, add that full path as > > a line to a text file. > > $ ri Find > - ------------------------------------------------------------ > Class: Find > The Find module supports the top-down traversal of a set of file > paths. > > For example, to total the size of all files under your home > directory, ignoring anything in a "dot" directory (e.g. > $HOME/.ssh): > > require 'find' > > total_size = 0 > > Find.find(ENV["HOME"]) do |path| > if FileTest.directory?(path) > if File.basename(path)[0] == ?. > Find.prune # Don't look any further into this > directory. > else > next > end > else > total_size += FileTest.size(path) > end > end > > - > ------------------------------------------------------------------------ > > Instance methods: > find, prune > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.2.2 (GNU/Linux) > > iD8DBQFE0u7ZmV9O7RYnKMcRAjIBAJ9+q41R2tvLhDGfjFNhHgNBVUGmqgCePUpM > UwoV4jQdlEZSTk+A6UZO/HE= > =hWcm > -----END PGP SIGNATURE-----