-
-
Save arjaneising/4150990 to your computer and use it in GitHub Desktop.
Revisions
-
derekkraan revised this gist
Nov 26, 2012 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,10 +9,15 @@ def new_filename(num, filename) end files = Dir['*'] shift = false dry_run = false ARGV.each do |arg| dry_run = true if arg == '-n' shift = $& if arg.to_s =~ /^[0-9]{1,4}$/ end unless shift puts 'invalid parameter; exiting' exit 1 end puts 'DRY RUN' if dry_run -
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ def new_filename(num, filename) if num.to_i < 9 "_0#{num.to_i+1}#{filename}" elsif num.to_i < 99 "_#{num.to_i+1}#{filename}" else "#{num.to_i+1}#{filename}" end end files = Dir['*'] shift = ARGV.first dry_run = false ARGV.each do |arg| dry_run = true if arg == '-n' end puts 'DRY RUN' if dry_run LESS_HUNDRED = /^_([0-9]{2})(.*)/ HUNDRED_PLUS = /^([1-9][0-9]{2})(.*)/ queued_moves = [] [LESS_HUNDRED, HUNDRED_PLUS].each do |regex| files.select { |file| regex =~ file }.each do |file| regex =~ file if $1.to_i > shift.to_i puts "renaming `#{file}` to `#{new_filename($1, $2)}`" File.rename file, "__temp_#{$1}" unless dry_run queued_moves << ["__temp_#{$1}", new_filename($1, $2)] end end end unless dry_run queued_moves.each do |move| File.rename move[0], move[1] end end