From: Sven Schott Date: 2009-11-05T07:44:45+09:00 Subject: Re: Merging mp3 files in Ruby --0016e64cd7ee63c0760477935bf1 Content-Type: text/plain; charset=ISO-8859-1 How about a hash or something like that? dir = ARGV[0] store = Hash.new Dir.foreach(dir) do |file| unless file =~ /^\./ num, name, ext = file.scan(/([0-9]+\-[0-9]+)\ ([A-Za-z0-9\ ]+)(\.mp3)/).flatten if store[name] store[name][:numbers] << num else store[name] = { :extension => ext, :numbers => [num] } end end end store.each do |name, properties| filename = name + properties[:extension] complete_file = File.open(filename, "w") store[name][:numbers].each do |num| part_filename = num + " " + name + properties[:extension] File.open(dir+"/"+part_filename, "r") do |f| complete_file.write(f.read) end end complete_file.close end On Thu, Nov 5, 2009 at 1:20 AM, Qu3ry Qu3ry wrote: > Bertram Scharpf wrote: > > Hi, > > > > Am Mittwoch, 04. Nov 2009, 17:57:24 +0900 schrieb Qu3ry Qu3ry: > >> Suppose I have the following files to group and merge, according to > >> their filenames. How to do it on Ruby? > >> > >> P.S In BASH, you can merge two mp3 files perfectly with the cat command. > >> # cat file1.mp3 file2.mp3 > file.mp3 > >> > > > > ruby -pe '' file1.mp3 file2.mp3 >file.mp3 > > > > Bertram > > How to iterate the mp3 files according to their names, so that files > with the same names are merged together? > > > -- > Posted via http://www.ruby-forum.com/. > > --0016e64cd7ee63c0760477935bf1--