Merging Text Files

I was a bit at a loss how to merge 22 different text files into one file. You see, I had a few PDF files that I converted to text files (I used Calibre). But I wasn’t sure how to combine them into one file.

There are several programs but making a *.bat file worked well. It was an answer found on the web after I ran into trouble with the two approaches I tried at the command line in Windows 11.

I simply saved this as a bat file in the folder with all the txt files after pasting it into a Text Editor:

@echo off
for /r %%i in (*.txt) do (
if not %%~nxi == output.txt (
echo %%~nxi >> output.txt
type “%%i” >> output.txt
echo. >> output.txt
echo. >> output.txt
)
)

When the bat file runs, it creates an output.txt file with the combined files.

Why Combine Text Files?

The reason I wanted to combine text files converted from PDF files was to get the content of a PDF into a single text file I could drop into an AI Knowledge Stack. Content in text format takes up a lot less space.

And, some web-based AI tools have file size or file upload limits. For example, you can only upload 10 files to a Google Gem. I’m still not absolutely sure that combining files into one is best for processing on the AI’s side, but it does make things easier in the sense of total files to upload.

🙂


Discover more from Another Think Coming

Subscribe to get the latest posts sent to your email.

Leave a comment