How to rename a file in Ruby?

后端 未结 5 1046
南方客
南方客 2020-12-13 03:22

Here\'s my .rb file:

puts \"Renaming files...\"

folder_path = \"/home/papuccino1/Desktop/Test\"
Dir.glob(folder_path + \"/*\").sort.each do |f|
    filename         


        
5条回答
  •  离开以前
    2020-12-13 04:11

    If you're running in the same location as the file you want to change

    File.rename("test.txt", "hope.txt")
    

    Though honestly, I sometimes I don't see the point in using ruby at all...no need probably so long as your filenames are simply interpreted in the shell:

    `mv test.txt hope.txt`
    

提交回复
热议问题