zoukankan      html  css  js  c++  java
  • Tcl脚本整理照片

    我那个媳妇啊,典型的只管照不管 理,32G的卡竟然被弄满了。

    费好大劲好不容易整理到电脑上,可是都是数字名字,看着都头疼,索性整理下。

    首先安装tcl编译环境tcl86,度娘搞的,然后开动:

     1 proc call_Deal {paths str} {
     2     cd $paths
     3     set strList ""
     4     catch {set strList [glob *.*]}
     5     set strreg "$str([0-9][0-9])"
     6     foreach strLine $strList {
     7         if {[regexp $strreg $strLine "" strMonth]} {
     8             set strtemp "$paths/$str$strMonth"
     9             if {[file exists $strtemp]} {
    10                 #        
    11             } else {
    12                 
    13                 file mkdir $strtemp
    14             }
    15             file copy -force "$paths/$strLine" "$strtemp/$strLine"
    16             file delete "$paths/$strLine"
    17         }
    18     } 
    19 }
    20 proc main {} {
    21     set path "E:\"
    22     set year "2018"
    23     cd $path
    24     set strList [list]
    25     catch {set strList [glob *]}
    26     foreach strLine $strList {
    27         if {-1 != [string first $year $strLine]} {
    28             append path $strLine
    29             break
    30         }
    31     }
    32     set year "2018"
    33 
    34    call_Deal "$path\$year" $year
    35    #set year "2017"
    36    #call_Deal "$path\$year" $year
    37    #set year "2016"
    38    #call_Deal "$path\$year" $year
    39    #set year "2015"
    40    #call_Deal "$path\$year" $year
    41    #set year "2014"
    42    #call_Deal "$path\$year" $year
    43 
    44 }
    45 set strErrInfo ""
    46 if {[catch {main} strErrInfo]} {
    47     error "error = $strErrInfo"
    48 }

    1-19行定义了一个处理函数,总体思路就是把文件名中的年月匹配出来然后添加到目录后面作为文件路径,如果路径不存在就创建,然后拷贝文件到新目录里,删除旧文件。

    22-31是因为我使用的编码方式调用的时候识别不了中文,所以处理下;如果直接双击脚本是不需要的,可直接运行。

    家里那台电脑CPU是04年的,照片的处理还是比较快的,就是视屏太慢了,整个跟拷贝时间差不太多,代码也没有经过优化,草稿就这样了,功能没问题。

    glob函数找的是所有文件,也可以进行后缀过滤,因为我拷贝的文件里只有照片和视频,所以匹配了所有文件。

  • 相关阅读:
    scala 基本语法
    HBase架构深度解析
    scala 面向对象之 继承
    探索 ConcurrentHashMap 高并发性的实现机制
    Spark 源码和应用开发环境的构建
    spark内存管理详解
    2020软件工程第一次作业 L
    实验 1:Mininet 源码安装和可视化拓扑工具 L
    代码阅读方法
    生活中的小感悟
  • 原文地址:https://www.cnblogs.com/WaterGood/p/8169248.html
Copyright © 2011-2022 走看看