Skip to content

Instantly share code, notes, and snippets.

@randy909
Last active May 30, 2016 12:49

Revisions

  1. randy909 revised this gist May 30, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion zero-padder.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Dir.glob('*.mp3') do |file|
    Dir.glob('*.{mp3,MP3}') do |file|
    match = file.match(/^(.+\()(\d+)(\).+)/)
    if (match == nil)
    puts "skipping #{file}"
    @@ -11,3 +11,4 @@
    File.rename(file, newfile)
    end


  2. randy909 revised this gist May 30, 2016. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion zero-padder.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,13 @@
    Dir.glob('*.mp3') do |file|
    front, num, back = file.match(/^(.+\()(\d+)(\).+)/).captures
    match = file.match(/^(.+\()(\d+)(\).+)/)
    if (match == nil)
    puts "skipping #{file}"
    next
    end
    front, num, back = match.captures
    num = num.rjust(2, '0')
    newfile = front + num + back
    puts "renaming #{file} to #{newfile}"
    File.rename(file, newfile)
    end

  3. randy909 created this gist May 29, 2016.
    7 changes: 7 additions & 0 deletions zero-padder.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    Dir.glob('*.mp3') do |file|
    front, num, back = file.match(/^(.+\()(\d+)(\).+)/).captures
    num = num.rjust(2, '0')
    newfile = front + num + back
    puts "renaming #{file} to #{newfile}"
    File.rename(file, newfile)
    end