How to mass rename files in ruby

前端 未结 5 1240
梦谈多话
梦谈多话 2021-02-20 02:21

I have been trying to work out a file rename program based on ruby, as a programming exercise for myself (I am aware of rename under linux, but I want to learn Ruby, and rename

5条回答
  •  悲&欢浪女
    2021-02-20 03:09

    I made a small script to rename the entire DBZ serie by seasons and implement this:

    count = 1
    new_name = "Dragon Ball Z S05E"
    format_file = ".mkv"
    Dir.glob("dragon ball Z*").each do |old_name|
      File.rename(old_name, new_name + count.to_s + format_file)
      count += 1
    end
    

    The result would be: Dragon Ball Z S05E1 Dragon Ball Z S05E2 Dragon Ball Z S05E3

提交回复
热议问题