Skip to content

Instantly share code, notes, and snippets.

@ciaranarcher
Created January 13, 2014 19:58
Show Gist options
  • Save ciaranarcher/8406880 to your computer and use it in GitHub Desktop.
Save ciaranarcher/8406880 to your computer and use it in GitHub Desktop.
Concatenate any number of files
(defn cat-many [out files]
(map #(with-open [o (io/output-stream out)]
(io/copy (io/file %) o)) files))
(cat-many "/tmp/ciaran.mp3" '("/tmp/test-recording-1.mp3" "/tmp/test-recording-2.mp3"))
@clementlefevre
Copy link

i managed to make it work by adding the option :append true

(defn cat-many [out files]
  (map #(with-open [o (io/output-stream out :append true)]
          (io/copy (io/file %) o )) files))

@jsa-aerial
Copy link

you want to wrap the file processing within the with-open. Then you don't need the :append since you won't be opening and closing the file each time. So, something like

(defn cat> [files outfile]
  (with-open [out (jio/output-stream outfile)]
    (doseq [f files]
      (jio/copy (jio/file f) out))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment