【发布时间】:2010-05-13 21:03:16
【问题描述】:
我有以下代码,但每次到达函数末尾时都会崩溃,但它成功提取所有文件并将它们放在正确的位置。
require "zip"
function ExtractZipAndCopyFiles(zipPath, zipFilename, destinationPath)
local zfile, err = zip.open(zipPath .. zipFilename)
-- iterate through each file insize the zip file
for file in zfile:files() do
local currFile, err = zfile:open(file.filename)
local currFileContents = currFile:read("*a") -- read entire contents of current file
local hBinaryOutput = io.open(destinationPath .. file.filename, "wb")
-- write current file inside zip to a file outside zip
if(hBinaryOutput)then
hBinaryOutput:write(currFileContents)
hBinaryOutput:close()
end
end
zfile:close()
end
-- call the function
ExtractZipAndCopyFiles("C:\\Users\\bhannan\\Desktop\\LUA\\", "example.zip", "C:\\Users\\bhannan\\Desktop\\ZipExtractionOutput\\")
为什么每次到达终点都会崩溃?
【问题讨论】:
-
它崩溃的确切点是什么?
-
@lhf:我尝试了代码,这是 Lua 崩溃的原因:“lua.exe 已停止工作”-“在线检查解决方案/关闭程序/调试程序”。所以,从字面上看,Lua 崩溃了。
-
有时堆栈跟踪在这种情况下有很大帮助。我认为即使在 Windows 上,您也可以从“程序崩溃”对话框的深处提取它。
标签: lua zip extraction