tcl实现批量压缩文件夹

  tcl脚本本身对字符串的处理比较简单,所以想着用这个也实现下:

proc main {} {
    puts  "请输入路径:"
    set strpath "E:\123"
    set exepath [pwd]
    append exepath "/bin/7z.exe"
    set exepath [string map {"/" "\"} $exepath]
    puts $exepath
    set filelist ""
    cd $strpath
    #puts $strpath
    catch {set filelist [glob *]}
    if {"" == $filelist} {
        puts "目录为空"
        return
    }
    foreach strLine $filelist {
        set strtemp "$strpath\$strLine"
        if {[file isdirectory $strLine]} {
            set str "$strtemp"
            append str ".zip"
            puts $str
            #exec这里不需要判断目录是否有空格,tcl自动处理
            exec $exepath a -tzip $str $strtemp
        }
    }
    puts "_end"
}
set strErrInfo ""
if {[catch {main} strErrInfo]} {
    error "error = $strErrInfo"
}
原文地址:https://www.cnblogs.com/WaterGood/p/8614185.html