以某种格式重命名目录下所有文件(ruby实现)

2019-04-15 16:15发布

 path = "F:\pic"
$prefix = "pp"def renameFile(path)
serial = 1
    Dir.foreach(path) do |f|        fullfilename = path + "/" + f
       if f == "." or f == ".."
       elsif File.directory?(fullfilename)
       elsif File.file?(fullfilename)
           File.rename fullfilename, "#{path}/#{$prefix}%03d.jpg" % [serial]
           serial = serial + 1
       end
    endend  #def renameFile(path)

renameFile(path)