«SCD/TXT File merger» by prko
on 01 Mar'26 16:03 in1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
( var extension, scriptPath, currentDir, sourceFiles, outputFileName; extension = "scd"; // "txt" scriptPath = thisProcess.nowExecutingPath; if (scriptPath.isNil) { "Error: This script must be saved on disk.".error; } { currentDir = scriptPath.dirname; outputFileName = "_merged_." ++ extension; sourceFiles = (currentDir +/+ "*." ++ extension).pathMatch.select { |path| (path.basename != outputFileName) and: { path.basename != scriptPath.basename } }.sort; ("Number of" + "." ++ extension + "files found:" + sourceFiles.size).postln; /* Open the output file once and write content incrementally */ File.use(currentDir +/+ outputFileName, "w", { |outFile| sourceFiles.do { |path| var content, fileName; fileName = path.basename; /* Read */ content = File.readAllString(path); if (content.notNil) { /* Write */ outFile.write("\n/* " ++ fileName ++ " */\n\n" ++ content ++ "\n\n"); ("Appended:" + fileName).postln; } { ("Warning: Could not read" + fileName).warn; } }; "Success! All files merged into:" + outputFileName }) }; )
reception
comments