Lua 批量修改文件夹下文件名


local s = io.popen("dir C:\\Users\\lizhiyuan\\Desktop\\国家知识产权局ftp法律状态数据\\data /b/s")
local filelist = s:read("*a")


local start_pos = 0


while 1 do
	_,end_pos,line = string.find(filelist, "([^\n\r]+.xml)", start_pos)


	if not end_pos then
		break
	end

	oldname = string.match(line,"0_.-.xml")
	newname = string.gsub(oldname,"135169","119")
	os.rename(line, string.format("C:\\Users\\lizhiyuan\\Desktop\\国家知识产权局ftp法律状态数据\\data\\%s",newname))

	start_pos = end_pos+1
end

Lua 批量修改文件夹下文件名_第1张图片

你可能感兴趣的:(lua)