XP的资源管理器对文件名进行排序时,对于含数字的文件名(字符串),会按数值的大小进行排序。如:升序时,“文件2”会排在“文件12”的前面。我也编写了一个功能类似的函数,与大家共享。 例: _$ (setq sl1 '("4" "5" "6" "1" "2" "3" "10" "11" "12" "7" "8" "9" "13" "14" "15") sl2 '("4a" "5a" "6a" "1a" "2a" "3a" "10a" "11a" "12a" "7a" "8a" "9a" "13a" "14a" "15a") sl3 '("A4" "A5" "A6" "A1" "A2" "A3" "A10" "A11" "A12" "A7" "A8" "A9" "A13" "A14" "A15") sl4 '("B4c" "B5c" "B6c" "B1c" "B2c" "B3c" "B10c" "B11c" "B12c" "B7c" "B8c" "B9c" "B13c" "B14c" "B15c") ) _$ (TBC:Sort sl1 '<) ("1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15") _$ (TBC:Sort sl2 '<) ("1a" "2a" "3a" "4a" "5a" "6a" "7a" "8a" "9a" "10a" "11a" "12a" "13a" "14a" "15a") _$ (TBC:Sort sl3 '<) ("A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "A13" "A14" "A15") _$ (TBC:Sort sl4 '<) ("B1c" "B2c" "B3c" "B4c" "B5c" "B6c" "B7c" "B8c" "B9c" "B10c" "B11c" "B12c" "B13c" "B14c" "B15c") _$ (TBC:Sort (append sl4 sl3 sl2 sl1) '<) ("1" "1a" "2" "2a" "3" "3a" "4" "4a" "5" "5a" "6" "6a" "7" "7a" "8" "8a" "9" "9a" "10" "10a" "11" "11a" "12" "12a" "13" "13a" "14" "14a" "15" "15a" "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "A13" "A14" "A15" "B1c" "B2c" "B3c" "B4c" "B5c" "B6c" "B7c" "B8c" "B9c" "B10c" "B11c" "B12c" "B13c" "B14c" "B15c") 函数如下: ;调用说明:lst-字符串列表;func-排序方式。“'<”为升序,“'>”为降序。 (defun TBC:Sort (lst func / Split CompFunc tmp) (defun Split (str / tmp i n p x len lst1 lst) (setq tmp (vl-string->list str) lst1 (mapcar '(lambda (x) (and (<= 48 x) (<= x 57))) tmp) n (length lst1) i 0 ) (while (< i n) (setq x (nth i lst1) i (1+ i) ) (if (= i 1) (setq p 1 len 1 ) ;else (if (= x (nth (- i 2) lst1)) (setq len (1+ len)) ;else (setq tmp (substr str p len) tmp (if x tmp (atoi tmp) ) lst (append lst (list tmp)) p i len 1 ) ) ;if ) ;if ) ;while (if (> n 0) (setq tmp (substr str p len) tmp (if x (atoi tmp) tmp ) lst (append lst (list tmp)) ) ) lst ) (defun CompFunc (lst1 lst2 / tmp do flag i n el1 el2 typ1 typ2) (setq i 0 n (min (length lst1) (length lst2)) do T ) (while (and do (<= i n)) (setq el1 (nth i lst1) typ1 (type el1) el2 (nth i lst2) typ2 (type el2) i (1+ i) ) (if (= typ1 typ2) (setq do (= el1 el2) flag (eval (list func el1 el2)) ) ;else (setq do nil flag (or (= typ1 'nil) (= typ2 'STR)) ) ) ;if ) ;while flag ) (setq tmp (mapcar 'Split lst) tmp (vl-sort-i tmp 'CompFunc) tmp (mapcar '(lambda (x) (nth x lst)) tmp) ) tmp ) |