How to mass rename files in ruby

前端 未结 5 1237
梦谈多话
梦谈多话 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:19

    I used the accepted answer to fix a bunch of copied files' names.

    Dir.glob('./*').sort.each do |entry|
      if File.basename(entry).include?(' copy')
        newEntry = entry.gsub(' copy', '')
        File.rename( entry, newEntry )
      end
    end
    

提交回复
热议问题