(defun files-in-below-directory (directory) "List the .el files in DIRECTORY and in its sub-directories." ;; Although the function will be used non-interactively, ;; it will be easier to test if we make it interactive. ;; The directory will have a name such as ;; "/usr/local/share/emacs/22.1.1/lisp/" (interactive "DDirectory name: ") (let (el-files-list (current-directory-list (directory-files-and-attributes directory t))) ;; while we are in the current directory (while current-directory-list (cond ;; check to see whether filename ends in '.el' ;; and if so, add its name to a list. ((equal ".org" (substring (car (car current-directory-list)) -4)) (setq el-files-list (cons (car (car current-directory-list)) el-files-list))) ;; check whether filename is that of a directory ((eq t (car (cdr (car current-directory-list)))) ;; decide whether to skip or recurse (if (equal "." (substring (car (car current-directory-list)) -1)) ;; then do nothing since filename is that of ;; current directory or parent, "." or ".." () ;; else descend into the directory and repeat the process (setq el-files-list (append (files-in-below-directory (car (car current-directory-list))) el-files-list))))) ;; move to the next filename in the list; this also ;; shortens the list so the while loop eventually comes to an end (setq current-directory-list (cdr current-directory-list))) ;; return the filenames el-files-list))
定位到保存 org 文件的目录,做一下转换:
1 2 3 4 5 6
(cl-loop for file in (files-in-below-directory "d:/TOTALCMD/tools/emacs/home/documents/blog/blog/") do (when file (with-current-buffer (find-file-noselect file) (org-export-to-file 'gfm (concat file ".md")))))