Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenating multiple files in emacs

Is there a fast (automatic) way to create one long file from all of the files in a directory using emacs? IE

>Text_1.txt

>{contents of Text_1}

>Text_2.txt

>{contents of text2}


>FinalResult.txt
>{contents of Text_1
>contents of Text2}
like image 919
LinkReincarnate Avatar asked Aug 20 '13 23:08

LinkReincarnate


1 Answers

How about this:

(defun insert-my-files ()
  (interactive)
  (let ((dir (read-directory-name "Directory to insert: ")))
    (mapc #'(lambda (file) 
              (let ((file-full (concat dir file)))
                (insert-file-contents file-full)))
          (cddr (directory-files dir)))))

Call it with M-x insert-my-files, and it will insert the contents of the directory you supply.

like image 112
Tyler Avatar answered Sep 17 '22 14:09

Tyler