open files in a directory and then find someword in the text tcl tk


cd /home/Desktop/Bl


set files [glob *]
set sofar 0

foreach f $files {
## start to read in the file name
  set sofar 0
  set fhandle [open [file join /home/Desktop/Bl/ $f] r]
  while {[gets $fhandle lyne] > -1} {
  incr sofar
  if {[regexp "files" $lyne ] >0 } {
   puts "The file $f has the keywords 'files' at line $sofar"
     }
   }
}

posted @ 2011-04-28 14:13  greencolor  阅读(123)  评论(0编辑  收藏  举报