Unzip/zip files (on Windows) without use of xop (using JScript)

Sometimes we need to unzip files without being able to rely on presence of zip.xop or any other Igor support.
After searching around on Windows forums I have found scripting method which, based on reports, should work on all currently used versions of Windows and be relatively reliable. I was able to test only on Windows 7 for now.
The script will need to be modified for specific use. At this moment it expects the zip file to be located on Desktop folder of current user. It also creates statically defined Folder for the unzipped files, which is prone to problems if the folder name is not unique. It allows the original zip file to be deleted or left there. Lot more can be done to make this more flexible and error-proof.
The code uses JScript from https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/z…
and instructions how to use from
http://stackoverflow.com/questions/28043589/how-can-i-compress-zip-and-…
All glory for those methods and scripts goes to npocmaka@gmail.com

The function CreateZipjsbat() is in the attached CreateZipsjBat.ipf, it is relatively large number of lines and it does not fit in the snippets size range.

Function UnzipFileOnDesktop(ZipFileName, NewDataFolderName, deleteSource)
    string ZipFileName, NewDataFolderName
    variable deleteSource
    //create Path to Desktop
    NewPath/O Desktop, SpecialDirPath("Desktop", 0, 0, 0 )
    //check that the file exists
    GetFileFolderInfo /P=Desktop /Q/Z=1 ZipFileName
    if(V_Flag!=0)
        Abort "Zip file not found on Desktop"
    endif  
    //create the command file on the desktop, this is Zipjs.bat per
    //from https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/z…;
    DoWindow zipjsbat
    if(V_Flag==0)
        CreateZipjsbat()   
    endif
    SaveNotebook/O/P=Desktop zipjsbat as "zipjs.bat"
    DoWindow/K zipjsbat
    //created the zipjs.bat command file which will unzip the file for us, note must kill the internal Notebook
    //or Igor will held the file and Windows will throw errors
    //now create cmd in line with
    //             zipjs.bat unzip -source C:\myDir\myZip.zip -destination C:\MyDir -keep no -force no
    // the destination folder is created by the script.
    // -keep yes will keep the content of the zip file, -force yes will overwrite the tempfolder for the data if exists
    // be careful, -force yes will wipe out the destination, if exists, so make sure the data are directed to non-existing folder.
        // later mod - put the unzipped file in temporary folder and create proper zip folder on the desktop. Cleaner
    string strToDesktop = SpecialDirPath("Desktop", 0, 1, 0 )
    string strToTemp     = SpecialDirPath("Temporary", 0, 1, 0 )
        string shortZipFileName= stringFromList(ItemsInList(ZipFileName,":")-1, ZipFileName,":")
    string cmd = strToDesktop+"zipjs.bat unzip -source "
    cmd +=strToDesktop+ shortZipFileName +" -destination "
    cmd +=strToTemp+"ZipFileTempFldr -keep yes -force yes"
    ExecuteScriptText cmd
        // now the unzipped data are in temporary:ZipFileTempFldr
    //delete the batch file to clean up...
    if(deleteSource)
        DeleteFile /P=Desktop /Z  ZipFileName      
    endif
    //now create the folder IgorCode is in the Desktop/NewDataFolderName
    //and we need it in Desktop...
        //create new folder which user wants
    NewPath /C /O/Q/Z tempForIgorCode, strToDesktop+NewDataFolderName
        //and copy the data there.
    cmd ="Xcopy  /E /I "+strToTemp+"ZipFileTempFldr\\shortZipFileName\\*    "+strToDesktop+ NewDataFolderName
    ExecuteScriptText cmd
        //note: cannot delete the ZipFileTempFldr folder as that action in Igor throws many warnings to users, so this leaves garbage in the user temporary folder.
end
CreateZipsjBat.ipf

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More