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
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
        Abort "Zip file not found on Desktop"
    //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
    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...
        DeleteFile /P=Desktop /Z  ZipFileName      
    //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.
CreateZipsjBat.ipf (49.74 KB)

I use this method a lot , in IP9 there needs to be a minor tweak to the CreatZipsjBat.ipf. After the NewNotebook line there should be a command to not write an byte order mark i.e.

String nb = "zipjsbat"
Notebook $nb writeBOM=0 // insert this for IP9, should have no effect in earlier versions?
// ...

Thanks to tech support for that.




Maybe, but if you want to zip folders, add things to existing archives, interrogate archives, unzip only part of an archive, don't have IP9, don't have Win 10 or Mac, don't want to change existing code, don't want to rely on %TEMP%.... this batch file route works a treat.




Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More