{
   "description" : "",
   "ancestor_list" : [],
   "author" : "prko",
   "name" : "SCD/TXT File Merger (script-relative, no GUI)",
   "code" : "(\r\nvar extension, scriptPath, currentDir, sourceFiles, outputFileName;\r\n\r\nextension = \"scd\"; // \"txt\"\r\n\r\nscriptPath = thisProcess.nowExecutingPath;\r\n\r\nif (scriptPath.isNil) {\r\n\t\"Error: This script must be saved on disk.\".error;\r\n} {\r\n\tcurrentDir = scriptPath.dirname;\r\n\toutputFileName = \"_merged_.\" ++ extension;\r\n\r\n\tsourceFiles = (currentDir +/+ \"*.\" ++ extension).pathMatch.select { |path|\r\n\t\t(path.basename != outputFileName) and: { path.basename != scriptPath.basename }\r\n\t}.sort;\r\n\r\n\t(\"Number of\" + \".\" ++ extension + \"files found:\" + sourceFiles.size).postln;\r\n\r\n\t/* Open the output file once and write content incrementally */\r\n\tFile.use(currentDir +/+ outputFileName, \"w\", { |outFile|\r\n\t\tsourceFiles.do { |path|\r\n\t\t\tvar content, fileName;\r\n\t\t\tfileName = path.basename;\r\n\r\n\t\t\t/* Read */\r\n\t\t\tcontent = File.readAllString(path);\r\n\r\n\t\t\tif (content.notNil) {\r\n\t\t\t\t/* Write */\r\n\t\t\t\toutFile.write(\"\\n/* \" ++ fileName ++ \" */\\n\\n\" ++ content ++ \"\\n\\n\");\r\n\t\t\t\t(\"Appended:\" + fileName).postln;\r\n\t\t\t} {\r\n\t\t\t\t(\"Warning: Could not read\" + fileName).warn;\r\n\t\t\t}\r\n\t\t};\r\n\t\t\"Success! All files merged into:\" + outputFileName\r\n\t})\r\n};\r\n)",
   "id" : "1-5iK",
   "is_private" : null,
   "labels" : []
}
