Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created June 22, 2010 18:19
Show Gist options
  • Save itspriddle/448848 to your computer and use it in GitHub Desktop.
Save itspriddle/448848 to your computer and use it in GitHub Desktop.
# Sort messages in this folder
#
# Example:
# Before Sort: msg0002, msg0005, msg0010, msg0020
# After Sort: msg0000, msg0001, msg0002, msg0003
def sort!
temp = []
messages.each_with_index do |message, index|
# message.files is an array of files [msg0000.{txt,wav}]
message.files.each do |file|
ext = File.extname(file)
filename = "#{@path}/temp_msg%04d#{ext}" % index
temp << filename
File.rename(file, filename)
end
end
temp.each do |t|
filename = t.sub('temp_msg', 'msg')
File.rename(t, filename)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment