Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

combine multiple text files, _+ filenames_, into a single text file

Writer Emily Wong

I would like to combine a handful of text files, but with titles (EDIT: filenames). Ideally, something like

* a filename
contents of file
...
* another filename
contents of file
...
etc... 

I am in windows (not DOS), but have access to powershell, pandoc, emacs, cygwin, or anything else you recommend. (Clearly I'm a newb trying out org-mode.)

I can easily put them all in one folder. But I would like to avoid typing the name of each file. If a bat file is recommended, I have never used one, but am willing to learn.

4

2 Answers

I am sure there is something more clever, but here is a powershell script will combine all files:

$files = (dir *.txt)
$outfile = "out.txt"
$files | %{ $_.FullName | Add-Content $outfile Get-Content $_.FullName | Add-Content $outfile
}

Is it efficient? Not terribly... but it will work in a pinch.

5

Inspired by the structure of Mitch's script, I've written a version for Unix-based environments, such as GNU/Linux and OS X:

find -regex '.*\.\(docx?\|org\|rtf\|te?xt\)$' | while read file
do echo "* $file" >> target-file.org cat "$file" | pandoc -t org >> target-file.org
done

(If you don't want to install pandoc, simply remove the pipe and command, | pandoc -t org.)

This script will find all files in the current directory and its subdirectories which have file extensions as described (.docx, etc).

For example, if the list includes fileA.text and fileB.rtf in subdirectory subd/, targetfile.org will receive lines such as:

* ./subd/fileA.text
<fileA's contents converted to an org file by pandoc>
* ./subd/fileB.rtf
<fileB's contents converted to an org file by pandoc>

I think this will leave target-file.org in a pretty good state for improving from within Emacs, without the script being too complicated. (Especially if you include the pandoc step.)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy