initial commit of bin scripts into git
This commit is contained in:
74
abs_to_rel.tcl
Executable file
74
abs_to_rel.tcl
Executable file
@@ -0,0 +1,74 @@
|
||||
proc UnBusy {} {
|
||||
. conf -cursor {}
|
||||
.dir_e conf -cursor {}
|
||||
.str_e conf -cursor {}
|
||||
.doit conf -state normal
|
||||
update
|
||||
}
|
||||
|
||||
proc Busy {} {
|
||||
. conf -cursor watch
|
||||
.dir_e conf -cursor watch
|
||||
.str_e conf -cursor watch
|
||||
.doit conf -state disabled
|
||||
update
|
||||
}
|
||||
|
||||
proc Err {str} {
|
||||
tk_dialog .dialog "Error" "$str" error 0 OK
|
||||
UnBusy
|
||||
}
|
||||
|
||||
proc Main {} {
|
||||
global dir str
|
||||
|
||||
set dir "c:/windows/desktop/myweb"
|
||||
set str "file:///c:\\windows\\desktop\\myweb\\"
|
||||
|
||||
label .dir_l -text "Directory to start searching in: "
|
||||
entry .dir_e -textvar dir -width 30
|
||||
label .str_l -text "String to delete: "
|
||||
entry .str_e -textvar str -width 30
|
||||
label .status -text "Status: Bored -- :^)" -relief groove
|
||||
button .doit -text "Do It" -command DoIt
|
||||
button .quit -text "Quit" -command {exit 0}
|
||||
grid .dir_l .dir_e
|
||||
grid .str_l .str_e
|
||||
grid .status -sticky ew -pady 10 -columnspan 2
|
||||
grid .doit .quit -sticky ew
|
||||
update
|
||||
}
|
||||
|
||||
proc DoIt {} {
|
||||
global dir str
|
||||
|
||||
.status conf -text "Finding files in $dir"
|
||||
Busy
|
||||
if { [catch {glob $dir/*.html} files] } {
|
||||
Err "Failed to find html files??? $files"
|
||||
return
|
||||
}
|
||||
|
||||
foreach filename $files {
|
||||
.status conf -text "Processing file: [file tail $filename]" ; update
|
||||
if { [catch {open "$filename" "r"} f] } {
|
||||
Err "$f"
|
||||
return
|
||||
}
|
||||
set data [read $f]
|
||||
close $f
|
||||
regsub -all -nocase "[list $str]" "$data" "" result
|
||||
|
||||
if { [catch {open "$filename.tmp" "w"} f] } {
|
||||
Err "$f"
|
||||
return
|
||||
}
|
||||
puts -nonewline $f "$result"
|
||||
close $f
|
||||
file rename -force $filename.tmp $filename
|
||||
}
|
||||
.status conf -text "Finished! ([clock format [clock seconds]])"
|
||||
UnBusy
|
||||
}
|
||||
|
||||
Main
|
||||
Reference in New Issue
Block a user