Sorting Sound Files using Ruby

ruby-2008.png

Consider you have 2,248 files in a directory, each containing one single sound program for your favourite Z1 synth. You need to load them into the synth individually, listen to them and to sort them in directories. Painful it would be.

Fortunately, all sounds are set to one of 18 predefined categories like guitar, synth hard, synth soft, piano, organ and the like. In the SysEx files, the category is coded into the 26. byte. So it was easy to sort the files into subdirectories using a couple of lines of Ruby code (sorry for the misformatting):



#! /usr/bin/ruby

require 'fileutils.rb'

def determineCategory( filename )
file = File.open( filename, "rb:binary" )
fileContents = file.read
category = fileContents[25] + 1
# puts filename, category
unless File.directory?(category.to_s)
Dir.mkdir( category.to_s )
end
FileUtils.mv( filename, category.to_s )
end

Dir.glob( '*.[Ss][Yy][Xx]' ) do |entry|
determineCategory entry
end

1 thought on “Sorting Sound Files using Ruby

Comments are closed.