Hey all:

I've been trying to figure out how I would go about doing the following task.

Basically, I have a folder with about 20,000 notepad files. My goal is to have one big word document, and append the contents of each notepad file to the word document. Each notepad file only has about 1 line of text (10-15 words).

I'm not looking for any code on how to do this, just loooking for a pseudo explanation on an approach i could take to tackle this.
Thanks :)

Dani AI

Generated

Quick practical plan for (builds on the scripting vs. OS-tool ideas from and without repeating their exact suggestions).

Start by choosing a target format and a safe workflow: produce one verified plain-text file first, then convert to Word if needed. That lets you validate ordering, encoding, and separators before touching a heavier .docx. Work in a streaming way (read one source file, write and flush to the single output) so memory never grows with file count.

Core steps (high level):

  • Enumerate and sort the files in the order you want (filename, creation time, or a natural numeric sort).
  • Open one output file in append/streaming mode and write in chunks (buffer ~200–1000 lines, then flush).
  • For each source file open read-only, read the single line, sanitize (trim, remove control chars), normalize encoding, then append a separator (blank line or filename header) and add to the buffer.
  • After the single text file is verified, convert to Word using a document library (programmatic .docx creation) rather than launching Word for every file.

Example pseudocode (conceptual):

buffer = []
for f in sorted_files(folder):
    line = read_and_decode_first_line(f)
    buffer.append(line + "\n\n")    # paragraph separator
    if len(buffer) >= 500:
        append_buffer_to(output_file, buffer)
        buffer.clear()
append_buffer_to(output_file, buffer)

Troubleshooting and cautions: handle mixed encodings and BOMs (try UTF‑8 with a fallback), log and skip locked or unreadable files, test on a 100–500 file subset first, and avoid automating Word on servers—use a library that writes .docx/RTF if this will run unattended. If you want provenance, prefix each appended paragraph with the source filename or timestamp.

Recommended Answers

All 2 Replies

get to the command line terminal, cd to the directory and type
copy /A *.txt all.txt
you will get one big text file. i'm not sure about microsoft (or any other) word, but it should be possible to convert a text file to a word processing document.

commented: Gotta love 1-line simplicity +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.