​ //** // Forcefully delete a folder. DeleteFolder also // works but if the user hasn't told Igor not to prompt // them before doing so then the tests won't finish running. // // BE CAREFUL USING THIS. //* Function ForceDeleteFolder(fullPathToFolder) String fullPathToFolder Variable error String platform = IgorInfo(2) String errorMessage String envInfoString StrSwitch (platform) Case "Windows": try // Do some setup. String tmpDir = SpecialDirPath("Temporary", 0, 0, 0) AbortOnValue (numtype(strlen(tmpDir)) != 0 || !(strlen(tmpDir) > 0)), 1 // Make sure that the directory we just got is, in fact, a directory. GetFileFolderInfo/Q tmpDir AbortOnValue (V_Flag >= 0 && !V_isFolder), 3 // Set an Igor symbolic path to the temporary directory. String tmpDirectoryPath = UniqueName("tmpPath", 12, 0) NewPath/Q $(tmpDirectoryPath), tmpDir AbortOnValue (V_flag), 5 // Setting of the new path failed. // Write a temporary batch file to the temporary directory that will // call the "rmdir" command from the command shell and save the // output of the command to a temporary file. String tempBatFileName, tempResultsFileName String tempBatFileFullPath, tempResultsFileFullPath Variable tempBatFileRefNum, tempResultsFileRefNum sprintf tempBatFileName, "IgorCommandScript_%.4u.bat", abs(trunc(StopMsTimer(-2))) Open/P=$(tmpDirectoryPath)/T=".bat"/Z=1 tempBatFileRefNum as tempBatFileName AbortOnValue (V_flag != 0), 7 // Add a path separator character to the end of the path, if necessary, and add on the file name. tempBatFileFullPath = ParseFilePath(2, tmpDir, ":", 0, 0) + tempBatFileName // Convert the path into a windows path that uses "\" as the path separator. tempBatFileFullPath = ParseFilePath(5, tempBatFileFullPath, "\\", 0, 0) // /s deletes all contents of directory and then the directory // /q prevents DOS from asking us if we're sure. String windowsFilePath = ParseFilePath(5, fullPathToFolder, "\\", 0, 0) if (strlen(windowsFilePath) <= 0) AbortOnValue 1, 8 endif fprintf tempBatFileRefNum, "rmdir \"%s\"/s /q \r\n", windowsFilePath Close tempBatFileRefNum // Call the batch file we just created. Timeout after 2 seconds if this doesn't succeed. String scriptText sprintf scriptText, "cmd.exe /C \"%s\"", tempBatFileFullPath ExecuteScriptText/W=2/Z scriptText // Check for an error. AbortOnValue (V_flag != 0), 9 // Delete the temporary batch file and temporary results file. DeleteFile/P=$(tmpDirectoryPath)/Z=1 tempBatFileName // If we get an error here we don't really care. We've already got // the goods, so just run. break catch error = -1 endtry Case "Macintosh": // This is a lot easier on the Macintosh because we can just use AppleScript. try // Figure out the POSIX path of the folder to delete. String posixPath = ParseFilePath(5, fullPathToFolder, "/", 0, 0) if (strlen(posixPath) > 0) String appleScriptCommand sprintf appleScriptCommand, "tell application \"Finder\" to delete ((POSIX file \"%s\") as alias)", posixPath ExecuteScriptText/Z appleScriptCommand AbortOnValue V_flag, 1 endif envInfoString = S_Value catch errorMessage = "Could not execute AppleScript command." print errorMessage error = -1 endtry break EndSwitch if (numtype(strlen(tmpDirectoryPath)) == 0) // Check for a null string KillPath/Z $(tmpDirectoryPath) endif return error End