require 'lfs'
local function _copySpineFile(rootPath, targetPath, lastEntry)
for entry in lfs.dir(rootPath) do
if entry ~= '.' and entry ~= '..' then
local path = rootPath .. '/' .. entry
local attr = lfs.attributes(path)
if attr.mode == 'directory' then
_copySpineFile(path, targetPath, entry)
else
if entry == lastEntry .. ".png" or entry == lastEntry .. ".atlas" or entry == lastEntry .. ".json" then
path = string.gsub(path, "/", "\\")
local newTargetPath = targetPath .. "/" .. lastEntry
newTargetPath = string.gsub(newTargetPath, "/", "\\")
lfs.mkdir(newTargetPath)
local cmdStr = "xcopy " .. path .. " " .. newTargetPath .. " 1>nul 2>nul"
os.execute(cmdStr)
end
end
end
end
end
--=======================test=======================
_copySpineFile("C:/Users/xxx/Desktop/needSpine", "C:/Users/xxx/Desktop/111")
--=======================test=======================