如何使用Lua提取文件?如何使用Lua從zip文件中提取文件?
更新:我現在有下面的代碼,但它每次到達函數結束時崩潰,但它成功提取所有文件並將它們放在正確的位置。
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\\")
爲什麼每次碰到碰撞時都會碰撞?
我不相信這會奏效。我想實際提取壓縮文件內的文件,而不僅僅是查看壓縮文件內的文件。 – 2010-05-13 18:18:10
提取是從檔案中讀取並寫入文件系統的過程。你需要寫入文件系統的指令嗎?如果是這樣,請參閱Lua'io'和'os'模塊。 – 2010-05-13 18:20:18
所以我必須讀取和寫入每個文件?也許我會更好的做一個Windows系統調用來解壓縮文件。 – 2010-05-13 18:22:14