#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 // Use modern global access method and strict wave access #pragma DefaultTab={3,20,4} // Set default tab width in Igor Pro 9 and later #pragma version = 1.0 // Loads zipped ibw files via drag-and-drop or a function call // https://www.wavemetrics.com/user/chozo Static Constant kVerbose = 0 Static Function BeforeFileOpenHook(refNum, fileNameStr, pathNameStr, fileTypeStr, fileCreatorStr, fileKind) Variable refNum, fileKind String fileNameStr, pathNameStr, fileTypeStr, fileCreatorStr If (StringMatch(fileNameStr,"*.zip")) PathInfo $pathNameStr LoadZippedIBW(S_path, fileNameStr) return 1 endif return 0 End //################################# Function LoadZippedIBW(filePath, fileName) String filePath, fileName Variable unzipError, i String tempFolder = SpecialDirPath("Temporary", 0, 0, 0) NewPath/O/Q tmpPath, tempFolder unzipError = unzipArchive(filePath+fileName, tempFolder) if (unzipError) Print "Could not unzip file " + fileName return -1 endif String tempFileList = IndexedFile(tmpPath, -1, "IGBW") if (strlen(tempFileList) > 0) for (i = 0; i < ItemsInList(tempFileList); i += 1) String currFile = StringFromList(i,tempFileList) LoadWave/O/Q/P=tmpPath currFile DeleteFile/Z/P=tmpPath currFile if (strlen(S_waveNames) > 0) Wave work = $StringFromList(0, S_waveNames) //PostProcessData(work, currFile) // post-process loaded wave endif endfor endif KillPath/Z tmpPath return 0 End //################################# // stripped down unzip procedure written by Tony Withers + Igor 9 support // https://www.wavemetrics.com/code-snippet/expand-zip-archive-platform-agnostic Static Function unzipArchive(archivePathStr, unzippedPathStr) String archivePathStr, unzippedPathStr GetFileFolderInfo /Q/Z archivePathStr if(V_Flag || V_isFile==0) printf "Could not find file %s\r", archivePathStr return -1 endif if(findlistItem(ParseFilePath(4, archivePathStr, ":", 0, 0), "zip;", ";", 0, 0) == -1) printf "%s doesn't appear to be a zip archive\r", ParseFilePath(0, archivePathStr, ":", 1, 0) return -1 endif #if(IgorVersion() >= 9) // in Igor 9 just use unZip and quit unzippedPathStr = RemoveEnding(unzippedPathStr,":") unzipFile/O/Z archivePathStr, unzippedPathStr return V_flag #endif String cmd if(stringmatch(StringByKey("OS", igorinfo(3))[0,2],"Win")) // Windows Variable WinVersion = str2num(StringByKey("OSVERSION", igorinfo(3))) if (WinVersion<6.2) // 6.2 = windows 8.0 Print "unzipArchive requires Windows 8 or later" return 0 endif archivePathStr = ParseFilePath(5, archivePathStr, "\\", 0, 0) unzippedPathStr = ParseFilePath(5, unzippedPathStr, "\\", 0, 0) cmd = "powershell.exe -nologo -noprofile -command \"& { Add-Type -A 'System.IO.Compression.FileSystem';" sprintf cmd "%s [IO.Compression.ZipFile]::ExtractToDirectory('%s', '%s'); }\"", cmd, archivePathStr, unzippedPathStr else // Mac archivePathStr = ParseFilePath(5, archivePathStr, "/", 0, 0) unzippedPathStr = ParseFilePath(5, unzippedPathStr, "/", 0, 0) sprintf cmd, "unzip %s -d %s", archivePathStr, unzippedPathStr sprintf cmd, "do shell script \"%s\"", cmd endif ExecuteScriptText /B/UNQ/Z cmd if (kVerbose) Print S_value // output from ExecuteScriptText endif return V_flag End