File MIES_Utilities_File.ipf

utility functions for file handling

Functions

string UniqueFileOrFolder(string symbPath, string baseName, string suffix = defaultValue)

Returns a unique and non-existing file or folder name.

Warning

This function must not be used for security relevant purposes, as for that the check-and-file-creation must be an atomic operation.

Parameters:
  • symbPath – symbolic path

  • baseName – base name of the file, must not be empty

  • suffix – file/folder suffix

variable IsDriveValid(string absPath)

Return true if the given absolute path refers to an existing drive letter.

string GetDrive(string path)

Return the drive letter of the given path (Windows) or the volume name (Macintosh)

variable CreateFolderOnDisk(string absPath)

Create a folder recursively on disk given an absolute path.

If you pass windows style paths using backslashes remember to always double them.

string GetBaseName(string filePathWithSuffix, string sep = defaultValue)

Return the base name of the file.

Given path/file.suffix this gives file.

Parameters:
  • filePathWithSuffix – full path

  • sep – [optional, defaults to “:”] character separating the path components

string GetFileSuffix(string filePathWithSuffix, string sep = defaultValue)

Return the file extension (suffix)

Given path/file.suffix this gives suffix.

Parameters:
  • filePathWithSuffix – full path

  • sep – [optional, defaults to “:”] character separating the path components

string GetFolder(string filePathWithSuffix, string sep = defaultValue)

Return the folder of the file.

Given path/file.suffix this gives path. The returned result has a trailing separator.

Parameters:
  • filePathWithSuffix – full path

  • sep – [optional, defaults to “:”] character separating the path components

string GetFile(string filePathWithSuffix, string sep = defaultValue)

Return the filename with extension.

Given path/file.suffix this gives file.suffix.

Parameters:
  • filePathWithSuffix – full path

  • sep – [optional, defaults to “:”] character separating the path components

string GetWindowsPath(string path)

Return the path converted to a windows style path.

string GetHFSPath(string path)

Return the path converted to a HFS style (aka “:” separated) path.

string ResolveAlias(string path, string pathName = defaultValue)

Recursively resolve shortcuts to files/directories.

Returns:

full path or an empty string if the file does not exist or the shortcut points to a non existing file/folder

string GetUniqueSymbolicPath(string prefix = defaultValue)

Return a unique symbolic path name.

string symbPath = GetUniqueSymbolicPath()
NewPath/Q/O $symbPath, "C:"

string GetAllFilesRecursivelyFromPath(string pathName, string extension = defaultValue)

Return a list of all files from the given symbolic path and its subfolders. The list is pipe (FILE_LIST_SEP) separated as the semicolon (;) is a valid character in filenames.

Note: This function does not work on MacOSX as there filenames are allowed to have pipe symbols in them.

Parameters:
  • pathName – igor symbolic path to search recursively

  • extension – [optional, defaults to all files] file suffixes to search for

string AskUserForExistingFolder(string baseFolder)

Open a folder selection dialog.

Returns:

a string denoting the selected folder, or an empty string if nothing was supplied.

variable HasEnoughDiskspaceFree(string diskPath, variable requiredFreeSpace)

Check that the given path on disk has enough free space.

Parameters:
  • diskPath – path on disk to check

  • requiredFreeSpace – required free space in GB

variable GetOpenZFlag()

Return a /Z flag value for the Open operation which works with automated testing.

variable SaveTextFile(string data, string fileName, string fileFilter = defaultValue, string message = defaultValue, string *savedFileName = defaultValue, variable showDialogOnOverwrite = defaultValue)

Saves string data to a file.

Parameters:
  • data[in] string containing data to save

  • fileName[in] fileName to use. If the fileName is empty or invalid a file save dialog will be shown.

  • fileFilter[in] [optional, default = “Plain Text Files (*.txt):.txt;All Files:.*;”] file filter string in Igor specific notation.

  • message[in] [optional, default = “Create file”] window title of the save file dialog.

  • savedFileName[out] [optional, default = “”] file name of the saved file

  • showDialogOnOverwrite[in] [optional, default = 0] opens save file dialog, if the current fileName would cause an overwrite, to allow user to change fileName

Returns:

NaN if file open dialog was aborted or an error was encountered, 0 otherwise

std::tuple<string, string> LoadTextFile(string fileName, string fileFilter = defaultValue, string message = defaultValue)

Load data from file to a string. The file size must be < 2GB.

Parameters:
  • fileName[in] fileName to use. If the fileName is empty or invalid a file load dialog will be shown.

  • fileFilter[in] [optional, default = “Plain Text Files (*.txt):.txt;All Files:.*;”] file filter string in Igor specific notation.

  • message[in] [optional, default = “Select file”] window title of the save file dialog.

Returns:

loaded string data and full path fileName

wave LoadTextFileToWave(string fullFilePath, string sep)

Load data from a file to a text wave.

Parameters:
  • fullFilePath[in] full path to the file to be loaded

  • sep[in] separator string that splits the file data to the wave cells, typically the line ending

Returns:

free text wave with the data, a null wave if the file could not be found or there was a problem reading the file

variable FileExists(string filepath)

Check wether the given path points to an existing file.

Resolves shortcuts and symlinks recursively.

variable FolderExists(string folderpath)

Check wether the given path points to an existing folder.

string GetFileVersion(string filepath)

Return the file version.

variable GetFileSize(string filepath)

Return the file size in bytes.

string HFSPathToPosix(string path)

Convert a HFS path (:) to a POSIX path (/)

The path must exist.

string HFSPathToWindows(string path)

Convert a HFS path (:) to a Windows path (\\)

string HFSPathToNative(string path)

Convert HFS path (:) to OS native path (\\ or /)

string GetSymbolicPathForDiagnosticsDirectory()

Return the name of a symbolic path which points to the crash dump directory on windows.

variable ShowDiagnosticsDirectory()
string SanitizeFilename(string name)

Sanitize the given name so that it is a nice file name.

wave LoadWaveFromDisk(string name)

Load the wave $name.itx from the folder of this procedure file and store it in the static data folder.

variable StoreWaveOnDisk(wave wv, string name)

Store the given wave as $name.itx in the same folder as this procedure file on disk.

string GetUserDocumentsFolderPath()

Returns the path to the users documents folder.

string CleanupExperimentName(string expName)

Cleanup the experiment name.

string CalcHashForFile(string path, variable method = defaultValue)

Calculate a cryptographic hash for the file contents of path.

Parameters:
  • path – absolute path to a file

  • method – [optional, defaults to HASH_SHA2_256] Type of cryptographic hash function, one of HASH_SHA2_256

variable CheckIfPathsRefIdenticalFiles(string list)

Check if the file paths referenced in list are pointing to identical files.

string GetProgramFilesFolder()

Return a path to the program folder with trailing dir separator.

Hardcoded as Igor does not allow to query that information.

Distinguishes between i386 and x64 Igor versions