zoukankan      html  css  js  c++  java
  • 查找某个时间点范围内改动的文件

    常常因为磁盘空间不足的原因,须要删除旧文件,因此希望有一个函数,可以查找到某个时间点之前的文件,并删除之。

    用newLISP来实现的话,须要相似这种功能:


    (define (location-file-based-on-modified-time dir-path from-seconds to-seconds file-op)
      (unless (directory? dir-path)
        (throw-error (string dir-path " folder does not exist"))
        )
      (set 'dir-path (make-sure-folder-path-end-of-slash dir-path))
      (recursive-access-dir dir-path file-op (list from-seconds to-seconds)))

    调用代码:

    ;; @[from-seconds, to-seconds)
    (define (show-file file-path ext-context)
      (set 'm-time ((file-info file-path) 6))
      (set 'from (ext-context 0))
      (set 'to (ext-context 1))
    
      (unless (and (>= m-time from) (< m-time to))
        (if (regex ".txt$" file-path)
    	(begin
    	 (println "---begin---")
    	 (println file-path)
    	 (println (string "modified time: " (date m-time)))
    	 (println (string "from time: " (date from)))
    	 (println (string "to time: " (date to)))
    	 (delete-file file-path)
    	 (println (sys-error))
    	 (println "---end---")))
        ))
    
    
    (set 'cur-time (date-value))
    (set 'five-hours-ago (- cur-time (* 3600 5)))
    ;;(println cur-time)
    ;;(println five-hours-ago)
    (catch (FILE:location-file-based-on-modified-time "/tmp" five-hours-ago cur-time show-file) 'result)
    (if result
      (println result))



    start-time指的是改动时间的開始, end-time指的是改动时间的结束,依照习惯,这是一个左闭右开区间: [start-time, end-time), 这两个时间都使用epoch表示。

    假设找到,则返回true, 否则返回nil.


  • 相关阅读:
    修改表的定义
    DataFrame.groupby()函数
    有限差分法
    Python之pandas库
    类:实验2家中的电视
    函数:使用函数指针操作函数
    函数:函数操作结构体通过按值传递以及按址传递,使用动态内存
    函数:使用数组名作为函数参数进行操作
    函数:使用递归实现阶乘
    函数:通过按值传递及传递结构地址操作结构
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4509992.html
Copyright © 2011-2022 走看看