[Ilugc] [Help] Renaming files through bash shell scripts

  • From: shakthimaan@xxxxxxxxx (Shakthi Kannan)
  • Date: Wed, 28 Oct 2015 14:28:36 +0530

Hi,

--- On Wed, Oct 28, 2015 at 12:56 PM, Baskar Selvaraj
<baskar at linuxpert.in> wrote:
| M2L01.mp4 should be renamed to M2L11.mp4 and
| M3L01.mp4 should be renamed to M3L21.mp4
\--

M1L10.mp4 can be renamed to M1L00.mp4? Here is a quickly hacked up Ruby script:

=== test.rb ===

#!/usr/bin/env ruby

Dir.glob("*.mp4").each do |f|
  new_f = f.dup
  new_f[3] = (f[1].to_i - 1).to_s

  File.rename(f, new_f)
end

=== END ===

SK

-- 
Shakthi Kannan
http://www.shakthimaan.com

Other related posts: