From: Robert Klemme Date: 2007-12-05T01:07:12+09:00 Subject: Re: Rubyisms wanted to shorten code in search program 2007/12/4, RichardOnRails : > Hi, > > Search on WindowsXP/SP2 didn't seem to locate a file is looking for. > As someone relatively new to Ruby, I wonder whether there are any > Rubyisms I could have used to cut down the the 80+ lines I took to > accomplish this task, given the USAGE requirement I posed in the > code. > > Thanks in Advance, > Richard > > # Search.rb > # K:/_Projects/Ruby/_Ruby_Tests/TestSearchDir/SearchWithArgs > > # USAGE: Search.rb -d DirPath [-f regexpFileNameSought] [-t > regexpTextSought] Just a quick hack without command line processing. dir = ... name_regexp = ... # may be null content_regexp = ... # may be null require 'find' Find.find dir do |file| path, base = File.split file next if name_regexp && name_regexp !~ base or content_regexp && context_regexp !~ File.read(file) puts file end For command line processing I'd use OptionParser. Kind regards robert