标签:blog ar 文件 2014 art sp 代码 log on
需求是几百个文件,命名规则类似下面的文件名:
dailydata_20140320.txt
注意删除上次运行的结果,也要注意有文件不存在的话需要出error.log日志。
代码如下:
#!/usr/bin/newlisp
(set ‘start-date "20140101 00:00")
(set ‘start-seconds (date-parse start-date "%Y%m%d %H:%M"))
(set ‘day-seconds (* 3600 24))
(if (file? "20140101_20140828.txt")
(delete-file "20140101_20140828.txt"))
(if (file? "error.log")
(delete-file "error.log"))
(set ‘x 0)
(while (< x 240)
(begin
(set‘ compute-date (date (+ (* day-seconds x) start-seconds) 0 "%Y%m%d"))
(set ‘file-name (string "dailydata_" compute-date ".txt"))
(if (file? file-name)
(begin
(set ‘file-content (read-file file-name))
(print file-content)
(append-file "20140101_20140828.txt" file-content)
)
(append-file "error.log" (string file-name " does not exist")))
(inc x)
))
(exit)
标签:blog ar 文件 2014 art sp 代码 log on
原文地址:http://blog.csdn.net/csfreebird/article/details/39373395