TCL脚本递归列出文件

来源:互联网 发布:超赢软件 编辑:程序博客网 时间:2024/05/16 05:10

proc ListFiles { dir } {
    if {![file exists $dir] || ![file isdirectory $dir]} {
        puts "$dir is not exist or not a directory!"
        return
    }
   
    set files [glob -nocomplain -- $dir/*]
   
    for {set i 0} {$i<[llength $files]} {incr i 1} {
        set fileName [lindex $files $i]
        if {[file isfile $fileName]} {
            if {[string equal -nocase [string range $fileName end-3 end] ".tcl"]} {
                puts "$fileName is a tcl script. Press the script."
            } else {
                puts "$fileName is not a tcl script!"
            }
        } elseif {[file isdirectory $fileName]} {
            puts "$fileName is a directory. Call self."
            ListFiles $fileName
        } else {
            puts "$fileName is not a directory or a tcl script!"
        }
    }
}

原创粉丝点击