names_to_numbers.rb: add --starting-number
authorColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Sat, 15 Jun 2013 23:36:02 +0000 (16:36 -0700)
committerColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Sat, 15 Jun 2013 23:38:41 +0000 (16:38 -0700)
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>

names_to_numbers.rb

index 0fac484..c41c316 100755 (executable)
@@ -19,6 +19,7 @@ class MyOptions
     opts.dry_run = false
     opts.num_digits = 2
     opts.extension = nil
+    opts.starting_number = 1
     $fu_args = { :verbose => true }
     opts.preserve_names = false
 
@@ -43,6 +44,10 @@ class MyOptions
               "Preserve the names while changing the numbers.") do |e|
         opts.preserve_names = true
       end
+      myparser.on("--starting-number NUMBER", "-N",
+              "The starting number (defaults to 1)") do |e|
+        opts.starting_number = e.to_i
+      end
     end
 
     parser.parse!(args)
@@ -76,7 +81,7 @@ def get_file_name(num)
 end
 
 def rename_files(file)
-  dst="#{get_file_name(1 + $total_files)}.#{$opts.extension}"
+  dst="#{get_file_name($opts.starting_number + $total_files)}.#{$opts.extension}"
   if (file != dst) then
     FileUtils.mv(file, dst, $fu_args)
   end