# UnzipItemToFile

Definition: | include builtins\LiteZip.e object res = UnzipItemToFile(atom hzip, ZIPENTRY ze, string filename="")
Description: | Extracts a file, automatically creating any directories and subdirectories as needed. hzip: the result of a successful call to UnzipOpenFile(). ze: the recent subject of a successful UnzipGetItem() or UnzipFindItem() call. filename: the output file, if omitted (or length 0) uses the value already in ze (see UnzipGetFileName). Returns ZR_OK (=0) or a string error message.
pwa/p2js: | Not supported
Example 1: | Copy
    include builtins\LiteZip.e

    atom hzip = UnzipOpenFile("phix.0.7.7.1.zip")
    UnzipSetBaseDir(hzip,"test")
    ZIPENTRY ze = new_ZIPENTRY()
    ?UnzipFindItem(hzip,ze,"readme.txt") -- prints 0 (ZR_OK)
    string filename = UnzipGetFileName(ze) -- `test\readme.txt`

    ?UnzipItemToFile(hzip,ze,filename)  -- writes "", prints 0 (ZR_OK)

    UnzipClose(hzip)
Example 2: | Copy
    include builtins\LiteZip.e

    atom hzip = UnzipOpenFile("phix.0.7.7.1.zip")
    ZIPENTRY ze = new_ZIPENTRY()
    integer numitems = UnzipGetItems(hzip,ze)
    UnzipSetBaseDir(hzip,"test")

    for i=1 to numitems do
        integer res = UnzipGetItem(hzip, ze, i-1)
    --  string filename = UnzipGetFileName(ze)
        res = UnzipItemToFile(hzip, ze)--, filename)
        printf(1,"\r%2d%%",{(i/numitems)*100})
    end for

    UnzipClose(hzip)
    puts(1,"\ndone\n")
As just shown, there is no need to obtain the filename for each entry, but you can if you want.
See Also: | UnzipOpenFile, ZIPENTRY, UnzipGetItems, UnzipSetBaseDir, UnzipGetItem, UnzipGetFileName, UnzipClose