`
suoyihen
  • 浏览: 1358558 次
文章分类
社区版块
存档分类
最新评论

用Lua递归修改目录及子目录里文件的扩展名

 
阅读更多
用PHP代理下载小说的时候,html扩展名全部被Google的浏览器保存成.php。这个很讨厌。
用Lua写个脚本来解决吧。


require'lfs'

local sep = "//"
function renamedir(path)
local i = 1 -- 这里是upvalue,每个子目录都不一样的哦,都从1开始数
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path..sep..file
print ("/t=> "..f.." <=")
local attr = lfs.attributes (f)
--assert (type(attr) == "table")
if attr.mode == "directory" then
renamedir(f)
else
if f:find('php') then
cmd = [[ren "]]..f..[[" ]]..[["txt]]..i..[[.html"]]
i = i + 1
print (cmd)
os.execute(cmd)
end
end
end
end
end

renamedir('.')

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics