|
Versions Of This Snippet::
Download a raw-text version of this code by clicking on "Download Version"
Latest Snippet Version: :1.0.1
# Joins all .piece files (eg. abc.ext.piece1, abc.ext.piece2 etc) in the current directory and creates a single file (eg. abc.ext)
# Does not do any error handling!
# Usage: ruby file_joiner.rb
class FileJoiner
def initialize
# sort the .piece filenames in the correct order i.e. if there are 10 .piece files in the current directory
# we need to ensure that abc.ext.piece2 (and not abc.ext.piece10) follows abc.ext.piece1
@pieces = Dir["*.piece*"].sort do |f1, f2|
f1.split("piece").pop.to_i <=> f2.split("piece").pop.to_i
end
joined_filename = @pieces[0].split("\.")[0..1].join("\.")
@joined_file = File.open(joined_filename, "wb")
end
def join
@pieces.each { |file| @joined_file << File.open(file, "rb").read }
@joined_file.close
end
end
FileJoiner.new.join
Submit a new versionYou can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..
|
||||||||||||||||||||||||||||||||||||
