From: Abhijeet Dharmapurikar Date: 2007-08-17T09:05:04+09:00 Subject: Re: file grep Thanks Felix I just had to change one line < paths.find_all{|path| File.basename == filename}.each do |match| > paths.find_all{|path| File.basename(path) == filename}.each do |match| but it worked like a charm. Regards, Abhijeet Felix Windt wrote: >> >> done >> >> >> How do I do this in ruby ? If possible (again if possible) >> explain what the code does. If not I will google and update >> what each line does. >> -- >> Posted via http://www.ruby-forum.com/. >> > > > Disclaimer: Reading the complete files in to arrays like this may cost a > bunch of memory depending on file size > > # read in an array that contains one element per line from the list of > filesnames > filenames = File.new("filenames.txt").readlines > # read in an array that contains one element per line from the list of > full > filepaths > paths = File.new("allfilespath.txt").readlines > # cycle through all filenames > filenames.each do |filename| > # File.basename with one argument returns the last element of the > filepath, so the filename in a path > # the find_all method from the Enumerable mixin passes each element of > the > collection to the block, and returns an array of those where the block > evaluates to true > paths.find_all{|path| File.basename == filename}.each do |match| > # cycle through the matches, and print them > puts "#{filename} matches #{match}" > end > end > > > HTH, > > Felix -- Posted via http://www.ruby-forum.com/.