[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
newlispfanclub.alh.net • View topic - sort in v10.7.0

sort in v10.7.0

Q&A's, tips, howto's

sort in v10.7.0

Postby csfreebird » Wed Jun 29, 2016 9:26 am

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
Last edited by csfreebird on Thu Jun 30, 2016 7:38 am, edited 1 time in total.
csfreebird
 
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing

Re: [bug]sort in v10.7.0

Postby ralph.ronnquist » Thu Jun 30, 2016 6:46 am

ralph.ronnquist
 
Posts: 216
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: [bug]sort in v10.7.0

Postby csfreebird » Thu Jun 30, 2016 7:38 am

Thanks. It's my bad. I use wrong variable files, but should be file-list.
There is no bug in sort function. My bug.
csfreebird
 
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest

cron