How to rename a file in Ruby?

后端 未结 5 1050
南方客
南方客 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条回答
  •  -上瘾入骨i
    2020-12-13 04:25

    Don't use this pattern unless you are ready to put proper quoting around filenames:

    `mv test.txt hope.txt`
    

    Indeed, suppose instead of "hope.txt" you have a file called "foo the bar.txt", the result will not be what you expect.

提交回复
热议问题