Lua修改文件名
local lfs = require "lfs"
local curPath = "..\\new\\"
local totalFile = 0
local strFormatContain = "xml_Format.xml"
function attrdir (path)
for file in lfs.dir(path) do
local oldName = file
local a,b = string.find(oldName,strFormatContain)
local newName = string.gsub(oldName,strFormatContain,"xml")
if a ~= nil then
print(" oldName: " .. oldName)
print(" newName: " .. newName)
local result = os.rename(curPath .. file,curPath .. newName)
if result then
totalFile = totalFile + 1
end
os.remove(curPath .. file,curPath .. oldName)
print("\n")
end
end
end
attrdir (curPath)
print("totalFile: " ,totalFile)