构建tk窗口应用程序进行文件搜索

时间:2015-01-15 07:33:12

标签: file recursion tcl tk proc

嗨我正在构建一个窗口工具,其中将有一个目录模式条目和一个返回条目,用于给出特定模式的文件数量并计算按钮命中,我将获得返回条目中的文件数量。enter image description here

代码是:

          package require Tk

          wm title . "Validating number of files"
          grid [ttk::frame .c -padding "3 3 12 12"] -column 0 -row 0 -sticky nwes
          grid columnconfigure . 0 -weight 1; grid rowconfigure . 0 -weight 1

          #takes the input value for directory_Pattern
          grid [ttk::entry .c.directory_Pattern -width 20 -textvariable directory_Pattern] -column 2 -row 1 -sticky we
          grid [ttk::entry .c.numberOfFiles -width 20 -textvariable numberOfFiles] -column 2 -row 2 -sticky we
          grid [ttk::button .c.glob-r -text "Calculate" -command glob-r] -column 3 -row 3 -sticky w

          grid [ttk::label .c.flbl -text "directory_Pattern"] -column 3 -row 1 -sticky w
          grid [ttk::label .c.islbl -text "is equivalent to"] -column 1 -row 2 -sticky e
          grid [ttk::label .c.mlbl -text "numberOfFiles"] -column 3 -row 2 -sticky w

          foreach w [winfo children .c] {grid configure $w -padx 5 -pady 5}
          focus .c.directory_Pattern

          bind . <Return> {glob-r}

          proc glob-r {{dir .} args} {
          if {[catch {
             set res {}
             foreach i [lsort [glob -nocomplain -dir $dir *]] {
             if {[file isdirectory $i]} {
                    eval [list lappend res] [eval [linsert $args 0 glob-r $i]]
             } else {
                    if {[llength $args]} {
                       foreach arg $args {
                       if {[string match $arg $i]} {
                          lappend res $i
                          break
                       }
                    }
                    } else {
                           lappend res $i
                      }
                   }
           }
         return $res
         set ::numberOfFiles [$res]
         }]!=""} {
         set ::numberOfFiles "no files are there"
         }
         }

但是当我进入&#34; E:* .tcl&#34;在directory_patter中,我得到了#34;没有文件存在&#34;在numberOfFiles上点击计算按钮。 有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

首次调用时,您需要将directory_Pattern传递给glob-r程序 - 此时它无处可去!

grid [ttk::button .c.glob-r -text "Calculate" -command {glob-r $directory_Pattern}] -column 3 -row 3 -sticky w