From: Michal Suchanek Date: 2009-08-25T19:20:23+09:00 Subject: Re: help directory name issue... 2009/8/25 Ahmet Kilic : >  I am searching inside of the files ,like this > >  unless /.*test/.match( file_name ) || /.*Test/.match( file_name ) >        text = File.read(file_name) >        text.scan(/find/) do |it| >        $files << ("#{it} ---> #{File.basename(file_name) } =====> > #{File.dirname(file_name)}") >  end > > I can list the keyword, file name and directory name with path name, > but i want > 1- file name without any extension.  for example : *.rb ,*.java, *.txt , > ... > 2- I want to output only last directory name. Not path name. for > example:  C:\\test\myfiles\, C:\\test\outputs\  .... so only I want to > output myfiles and outputs directory names I suggest you look at File::split, File::basename or String.split. > 3- i want to output the search keyword`s left and right side sentences > also. > I am not sure what that means. You can print the line containing a keyword easily with File.open(filename){|f| f.each_line{|l| STDOUT << l if l =~ keyword_regexp }} and if you want sentences you could possibly split on punctuation instead of newlines. HTH Michal