Chinaunix首页 | 论坛 | 博客
  • 博客访问: 183289
  • 博文数量: 43
  • 博客积分: 1150
  • 博客等级: 少尉
  • 技术积分: 450
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-29 15:52
文章分类

全部博文(43)

文章存档

2012年(18)

2011年(24)

2008年(1)

分类: LINUX

2011-08-03 17:59:29

;;递归的将某一目录下的某一扩展名的文件添加到一个变量中
(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)
)
阅读(1085) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~