From: Colin Patrick Mccabe Date: Sat, 28 Jun 2014 20:25:29 +0000 (-0700) Subject: names_to_numbers.rb: add --glob argument. X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bca78978097ea60affff1f4d7c79ba03697a3af4;p=cmccabe-bin names_to_numbers.rb: add --glob argument. Signed-off-by: Colin McCabe --- diff --git a/names_to_numbers.rb b/names_to_numbers.rb index c41c316..4538976 100755 --- a/names_to_numbers.rb +++ b/names_to_numbers.rb @@ -48,12 +48,19 @@ class MyOptions "The starting number (defaults to 1)") do |e| opts.starting_number = e.to_i end + myparser.on("--glob GLOB", "-g", + "Specify the glob expression to use. Example: '*/*.mp3'.") do |d| + opts.glob = d + end end parser.parse!(args) raise "invalid num_digits: #{opts.num_digits}" unless opts.num_digits > 0 - raise "must give an extension" unless opts.extension != nil + raise "must specify an extension" unless opts.extension != nil + if (opts.glob == nil) then + opts.glob = "*.#{$opts.extension}" + end return opts end end @@ -65,9 +72,8 @@ def pow(x, y) end return ret end -#.#{$opts.extension}").sort.each do |f| def file_iter - Dir.glob("*.#{$opts.extension}").sort.each do |f| + Dir.glob($opts.glob).sort.each do |f| yield f end end