Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > A little file searcher *mod*
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 19th September 19:06
tim
External User
 
Posts: 1
Default A little file searcher *mod*



http://wiki.tcl.tk/3751.html


proc ui {} {
entry .e -bg white -textvar search
bind .e <Return> {search $search .t}
bind .e <Up> {set search ""}
text .t -yscrollcommand ".y set" -bg white -wrap word
scrollbar .y -command ".t yview"

grid .e - -sticky ew
grid .t .y -sticky news
grid columnconfig . 0 -weight 1
grid rowconfig . 1 -weight 1
}
proc readfile {file varName} {
upvar \#0 $varName data
set fp [open $file]
set data [split [read $fp] \n]
close $fp
#wm title . $file
wm title . "File: $file"
}
proc search {re w} {
global data
$w delete 1.0 end
set n 0
foreach line $data {
if {[regexp -nocase -- $re $line]} {
$w insert end $line\n
incr n
}
}
$w insert end "Found $n lines"
$w see end
}
#readfile "FileSearcher.tcl" data
#readfile [lindex $argv 0] data
set f [lindex $argv 0]
#if {$f eq ""} { set f "FileSearcher.tcl" }
if {$f eq ""} { set f [tk_getOpenFile] } ;# MG
if {![file exists $f]} { exit } ;# MG
readfile $f data
ui

i want to be able to search C:\windows\system\drivers\etc\HOSTS by
default rather then having to browse to that file everytime.

I dunno how the modify the script above
  Reply With Quote


 


Reply


Thread Tools
Display Modes




666