From: Robert Klemme Date: 2009-08-25T18:01:56+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 > 3- i want to output the search keyword`s left and right side sentences > also. > > please help me. please! Pathname to the rescue: http://www.ruby-doc.org/stdlib/libdoc/pathname/rdoc/index.html Also, please look into $` (prematch) and $' (postmatch) and / or MatchData and Regexp#match. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/