Combining multiple files in emacs

Is there a quick (automatic) way to create one long file from all 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} 
+4
source share
2 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))))) 

Name it Mx insert-my-files , and it inserts the contents of the directory that you supply.

+4
source

I do not know, you would call it a quick way, but insert-file can be used to insert a file into an existing buffer.

In the specific case you are talking about, the fastest way is probably from the command line: cat * > FinalResult.txt

+2
source

Source: https://habr.com/ru/post/1498095/


All Articles