1 description
I want to find oldest files when free space is not enough and delete them until free space is enough. Thus I find all files under one folder tree recursively and sort them by modified time.
2 code
2.1 find all files and save them into one list called file-list
(define (add-file-list f)
(push f file-list -1)
)
(define (find-all-files clean-folder)
(setq file-list '())
(recursive-access-dir clean-folder add-file-list)
file-list
)
;; @arg dir-path must be ended with /
(define (recursive-access-dir dir-path file-op)
(dolist (nde (directory dir-path {^[^.]}))
(if (directory? (append dir-path nde))
(recursive-access-dir (append dir-path nde "/") file-op)
(file-op (append dir-path nde)))))
2.2 sort file-list using compare function
(define (compare-time file1 file2)
(letn (t1 (int ((file-info file1) 6))
t2 (int ((file-info file2) 6))
)
(<= t1 t2)
)
)
(sort files compare-time)
3 result
The following code print all files' modified time
(setq files (find-all-files clean-folder))
(dolist (f files)
(println "files: " f ", time: " ((file-info f) 6))
The second file usa.sh is newer than jstc.sh, but it's in fron of jstc.sh. I check my code a few times, guess this is a bug of sort function.
files: /home/dean/sshclient/nj/delotto.sh, time: 1459176252
files: /home/dean/sshclient/nj/usa.sh, time: 1459176253
files: /home/dean/sshclient/nj/jstc.sh, time: 1459176252
files: /home/dean/sshclient/nj/test.sh, time: 1459176243
files: /home/dean/sshclient/nj/tunnel_gitlab_nanjing.sh, time: 1459176252
files: /home/dean/sshclient/nj/mongodb.sh~, time: 1459176252
files: /home/dean/sshclient/nj/root@/train.html~, time: 1461292073
files: /home/dean/sshclient/nj/root@/theme-readtheorg-local.setup, time: 1461292073
files: /home/dean/sshclient/nj/root@/package.sh, time: 1461292073
files: /home/dean/sshclient/nj/root@/imgs/in/rec1.png, time: 1461292073
files: /home/dean/sshclient/nj/root@/imgs/in/rec1.dot~, time: 1461292073
files: /home/dean/sshclient/nj/root@/imgs/in/path1.dot, time: 1461292073
files: /home/dean/sshclient/nj/root@/imgs/in/path1.dot~, time: 1461292073
files: /home/dean/sshclient/nj/root@/imgs/in/path1.png, time: 1461292073
files: /home/dean/sshclient/nj/root@/imgs/in/rec1.dot, time: 1461292073
files: /home/dean/sshclient/nj/root@/imgs/newbie/colla/u1.dot, time: 1461292073
files: /home/dean/sshclient/nj/root@/imgs/newbie/colla/u2.png, time: 1461292073
files: /home/dean/sshclient/nj/root@/imgs/newbie/colla/u1.png, time: 1461292073
files: /home/dean/sshclient/nj/root@/imgs/newbie/colla/u2.dot, time: 1461292073
files: /home/dean/sshclient/nj/root@/js/bootstrap.min.js, time: 1461292073
files: /home/dean/sshclient/nj/root@/js/jquery.min.js, time: 1461292073
files: /home/dean/sshclient/nj/root@/package.sh~, time: 1461292073
files: /home/dean/sshclient/nj/root@/train.html, time: 1461292073
files: /home/dean/sshclient/nj/root@/graph-schema/in_graph.dot, time: 1461292073
files: /home/dean/sshclient/nj/root@/graph-schema/in_graph.dot~, time: 1461292073
files: /home/dean/sshclient/nj/root@/graph-schema/ddl-to-dot.lsp~, time: 1461292073
files: /home/dean/sshclient/nj/root@/graph-schema/ddl.sql, time: 1461292073
files: /home/dean/sshclient/nj/root@/graph-schema/convert.lsp, time: 1461292073
files: /home/dean/sshclient/nj/root@/graph-schema/graph.dot~, time: 1461292073
files: /home/dean/sshclient/nj/root@/graph-schema/graph.png, time: 1461292073
files: /home/dean/sshclient/nj/root@/graph-schema/in_graph.png, time: 1461292073
files: /home/dean/sshclient/nj/root@/graph-schema/convert.lsp~, time: 1461292073
files: /home/dean/sshclient/nj/root@/styles/lib/js/jquery.stickytableheaders.min.js, time: 1461292073
files: /home/dean/sshclient/nj/root@/styles/lib/js/stickytableheaders-license.txt, time: 1461292073
Created: 2016-06-29 Wed 17:23
sort in v10.7.0
-
- Posts: 107
- Joined: Tue Jan 15, 2013 11:54 am
- Location: China, Beijing
- Contact:
sort in v10.7.0
Last edited by csfreebird on Thu Jun 30, 2016 7:38 am, edited 1 time in total.
-
- Posts: 228
- Joined: Mon Jun 02, 2014 1:40 am
- Location: Melbourne, Australia
Re: [bug]sort in v10.7.0
The expression
is kind of dangling; at the time of execution files has no value, and the result of the sorting is not captured anyhow.
Perhaps you meant to have that expression as part of the result creation step 3:
Code: Select all
(sort files compare-time)
Perhaps you meant to have that expression as part of the result creation step 3:
Code: Select all
(setq files (sort (find-all-files clean-folder) compare-time))
-
- Posts: 107
- Joined: Tue Jan 15, 2013 11:54 am
- Location: China, Beijing
- Contact:
Re: [bug]sort in v10.7.0
Thanks. It's my bad. I use wrong variable files, but should be file-list.
There is no bug in sort function. My bug.
There is no bug in sort function. My bug.