;;递归的将某一目录下的某一扩展名的文件添加到一个变量中
(defvar test nil)
(setq test nil)
(defun test-recurse (base-dir &optional recurse match)
(mapc (lambda (f)
(let ((fd-p (file-directory-p f))
(fnd (file-name-nondirectory f)))
(if (and fd-p recurse
(not (string-match "^\\.+$" fnd)))
(test-recurse f recurse match)
(unless (or fd-p ;; this is a directory
(not (file-exists-p (file-truename f)))
(not (string-match match fnd)))
(pushnew f test)))))
(directory-files base-dir t )))
(test-recurse "D:/note" t (concat "^[^\\.].*\\.\\(" "org" ""))
(list test)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;递归的将一个文件递归的拷贝到某一目录下的所有子目录中
(defun copy-file-to ( file to)
(mapc (lambda(f)
(let ()
(if (and f
(not (string-match "^\\.+$" f))
(string-match (file-name-nondirectory to) (file-name-nondirectory f)))
(delete-file f)
;; (message "%s!!!!!!!!!!%s" (file-name-nondirectory to) f)
)))
(directory-files (file-name-directory to) t))
(copy-file file to t)
;;(message "copy file %s\n to %s\n" file to)
)
(defun test-recurse-d (base-dir &optional recurse match file)
(mapc (lambda (f)
(let ((fd-p (file-directory-p f))
(fnd (file-name-nondirectory f)))
(if (and fd-p recurse
(not (string-match "^\\.+$" fnd)))
(if (and (or (copy-file-to file (concat (file-name-as-directory f) (file-name-nondirectory file)) ) t)
(test-recurse-d f recurse match file))
())
())))
(directory-files base-dir t )))
(defun recurse-copy (base-dir file)
( interactive "Ddirectory:\nFfilename:")
(message "directory:%s filename:%s input " base-dir file)
(test-recurse-d base-dir t nil file)
)
阅读(1098) | 评论(0) | 转发(0) |