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

  • From: baskar@xxxxxxxxxxxx (Baskar Selvaraj)
  • Date: Wed, 28 Oct 2015 14:55:51 +0530

=== 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 ===

Hi,

Thanks for the script

The scripts works, but the results were different, if the value after L is < 10.

input:

M1L01.mp4
M1L02.mp4
M1L03.mp4
M1L04.mp4
M1L05.mp4
M2L01.mp4
M2L02.mp4
M2L03.mp4
M2L04.mp4
M2L05.mp4
M3L01.mp4
M3L02.mp4
M3L03.mp4
M3L04.mp4
M3L05.mp4

Output:

M1L01.mp4
M1L02.mp4
M1L03.mp4
M1L04.mp4
M1L05.mp4
M2L11.mp4
M2L12.mp4
M2L13.mp4
M2L14.mp4
M2L15.mp4
M3L21.mp4
M3L22.mp4
M3L23.mp4
M3L24.mp4
M3L25.mp4

S. Baskar

Other related posts: