发一下我自己的搜索文件的函数: (defun f-all-folders (dirname / addlist testlist firstitem fldlist count n dirlist someitem acaddir ) (if (vl-file-directory-p dirname) (progn (setq addlist nil testlist (list dirname) ) (while testlist (setq firstitem (car testlist) addlist (append addlist (list firstitem)) ) (if (setq fldlist (vl-directory-files firstitem nil -1)) (progn (setq count (length fldlist) n 0 dirlist nil ) (while (< n count) (setq someitem (nth n fldlist) acaddir (vl-filename-base (vl-filename-directory (findfile "acad.exe") ) ) ) ;; and 后面列出了你不想寻找的目录 (if (and (not (equal someitem ".")) (not (equal someitem "..")) (not (equal someitem "Windows")) (not (equal someitem acaddir)) ) (setq someitem (strcat firstitem "\\" someitem) dirlist (append dirlist (list someitem)) ) ) (setq n (1+ n)) ) (setq testlist (append testlist dirlist)) ) ) (setq testlist (cdr testlist)) ) addlist ) (alert "指定的目录名是无效的。") ) ) (defun f-all-files (dire / allfolders allfiles first localfiles basename ffname ) (if (equal (type dire) 'STR) (progn (setq allfolders (f-all-folders dire) allfiles nil ) (while allfolders (setq first (car allfolders) localfiles (vl-directory-files first nil 1) ) (while localfiles (setq basename (car localfiles) ffname (strcat first "\\" basename) allfiles (append allfiles (list ffname)) localfiles (cdr localfiles) ) ) (setq allfolders (cdr allfolders)) ) allfiles ) (alert "参数类型错误,不是字符串。") ) ) (defun f-find (dirspec basename / filedata surfiles matchstr firstfile) (if (equal (type basename) 'STR) (progn (setq filedata (f-all-files dirspec) surfiles nil matchstr (strcat "*" basename) ) (while filedata (setq firstfile (car filedata)) (if (wcmatch (strcase firstfile) (strcase matchstr)) (setq surfiles (append surfiles (list firstfile))) ) (setq filedata (cdr filedata)) ) surfiles ) (alert "参数类型错误,不是字符串。") ) ) 速度有点慢,请高手改进。 |