All templates
Text ManipulationIntermediate
Concatenate Text Files
Robomotion•Updated 6 months ago

Overview
Reads every .txt file in a directory and stitches their contents into a single output file. Useful for log rollups.
Concatenate Text Files
Reading data from multiple sources and consolidating it in a single file is standard in most document-related operations. Robomotion lets you automate these tasks and effortlessly transfer information across numerous documents.
What Concatenate Text Files can do
- Build paths (
Core.Programming.Function) — setsmsg.fixtures_dirunder$Home$/templates/.../fixturesandmsg.output_file_pathtofixtures/ConcatenatedFiles.txt. - Intro dialog (
Core.Dialog.MessageBox,info) titledDescriptionexplaining that the flow stitches multiple text files into one. - Seed list (
Core.Programming.Function) →msg.files_to_concatenate = [fixtures/part1.txt, fixtures/part2.txt]. - Clean previous output (
Core.FileSystem.Delete,continueOnError: true) againstmsg.output_file_path, thenCore.Flow.GoTointoLoop Start. - Iterate (
Core.Programming.ForEach) overmsg.files_to_concatenate→msg.current_file,msg.current_index. - Read (
Core.FileSystem.ReadFile,optBase64: false) frommsg.current_file→msg.current_file_contents. - Build output (
Core.Programming.Function) — derivesmsg.output_pathas<dirname of current_file>\\ConcatenatedFiles.txtand setsmsg.line_to_write = msg.current_file_contents + '\n'. - Append (
Core.FileSystem.WriteFile,optMode: append,optBase64: false) tomsg.output_path, thenCore.Flow.GoToback toLoop Start. - Completion dialog (
Core.Dialog.MessageBox,info) titledExample completed!once the iterator exits, thenCore.Flow.Stop.
Behind the scenes
- The output file lives in the directory of each source file — if the selected files come from multiple directories, each directory gets its own
ConcatenatedFiles.txt. This is intentional to match the ported behaviour. Core.FileSystem.WriteFileinappendmode is called once per source file, so a pre-existingConcatenatedFiles.txtis deleted up front to guarantee a clean start.- Each file's contents are suffixed with
\nbefore being appended so boundaries remain visible even when source files don't end with a newline. - The completion dialog sits on the iterator's exit edge, so it runs once after every file has been processed.