|
static String | getExecutablePath () |
|
static bool | exists (const String &file) |
| Method used to test if a file exists. More...
|
|
static bool | empty (const String &file) |
| Return true if the file does not exist or the file is empty. More...
|
|
static bool | rename (const String &from, const String &to, bool overwrite_existing=true, bool verbose=true) |
| Rename a file. More...
|
|
static bool | copyDirRecursively (const QString &from_dir, const QString &to_dir, File::CopyOptions option=CopyOptions::OVERWRITE) |
|
static bool | remove (const String &file) |
| Removes a file (if it exists). More...
|
|
static bool | removeDirRecursively (const String &dir_name) |
| Removes the subdirectories of the specified directory (absolute path). Returns true if successful. More...
|
|
static bool | removeDir (const QString &dir_name) |
| Removes the directory and all subdirectories (absolute path). More...
|
|
static String | absolutePath (const String &file) |
| Replaces the relative path in the argument with the absolute path. More...
|
|
static String | basename (const String &file) |
| Returns the basename of the file (without the path). More...
|
|
static String | path (const String &file) |
| Returns the path of the file (without the file name). More...
|
|
static bool | readable (const String &file) |
| Return true if the file exists and is readable. More...
|
|
static bool | writable (const String &file) |
| Return true if the file is writable. More...
|
|
static bool | isDirectory (const String &path) |
| Return true if the given path specifies a directory. More...
|
|
static String | find (const String &filename, StringList directories=StringList()) |
| Looks up the location of the file filename . More...
|
|
static bool | fileList (const String &dir, const String &file_pattern, StringList &output, bool full_path=false) |
| Retrieves a list of files matching file_pattern in directory dir (returns filenames without paths unless full_path is true) More...
|
|
static String | findDoc (const String &filename) |
| Resolves a partial file name to a documentation file in the doc-folder. More...
|
|
static String | getUniqueName (bool include_hostname=true) |
| Returns a string, consisting of date, time, hostname, process id, and a incrementing number. This can be used for temporary files. More...
|
|
static String | getOpenMSDataPath () |
| Returns the OpenMS data path (environment variable overwrites the default installation path) More...
|
|
static String | getOpenMSHomePath () |
| Returns the OpenMS home path (environment variable overwrites the default home path) More...
|
|
static String | getTempDirectory () |
| The current OpenMS temporary data path (for temporary files) More...
|
|
static String | getUserDirectory () |
|
static Param | getSystemParameters () |
|
static String | findDatabase (const String &db_name) |
|
static StringList | getPathLocations (const String &path=std::getenv("PATH")) |
| Extract list of directories from a concatenated string (usually $PATH). More...
|
|
static bool | findExecutable (OpenMS::String &exe_filename) |
| Searches for an executable with the given name (similar to where (Windows) or which (Linux/MacOS) More...
|
|
static String | findSiblingTOPPExecutable (const String &toolName) |
| Searches for an executable with the given name. More...
|
|
static const String & | getTemporaryFile (const String &alternative_file="") |
| Obtain a temporary filename, ensuring automatic deletion upon exit. More...
|
|
static bool | validateMatchingFileNames (const StringList &sl1, const StringList &sl2, bool basename=true, bool ignore_extension=true, bool strict=false) |
| Helper function to test if filenames provided in two StringLists match. More...
|
|
Basic file handling operations.
Copy directory recursively.
Copies a source directory to a new target directory (recursive). If the target directory already exists, files will be added. If files from the source already exist in the target, option
allows for the following behaviour:
OVERWRITE: Overwrite the file in the target directory if it already exists. SKIP: Skip the file in the target directory if it already exists. CANCEL: Cancel the copy process if file already exists in target directory - return false.
- Parameters
-
from_dir | Source directory |
to_dir | Target directory |
option | Specify the copy option (OVERWRITE, SKIP, CANCEL) |
- Returns
- True on success
Enumerator |
---|
OVERWRITE | |
SKIP | |
CANCEL | |
Extract list of directories from a concatenated string (usually $PATH).
Depending on platform, the components are split based on ":" (Linux/Mac) or ";" (Windows). All paths use the '/' as separator and end in '/'. E.g. for 'PATH=/usr/bin:/home/unicorn' the result is {"/usr/bin/", "/home/unicorn/"} or 'PATH=c:\temp;c:\Windows' the result is {"c:/temp/", "c:/Windows/"}
Note: the environment variable is passed as input to enable proper testing (env vars are usually read-only).
static const String& getTemporaryFile |
( |
const String & |
alternative_file = "" | ) |
|
|
static |
Obtain a temporary filename, ensuring automatic deletion upon exit.
The file is not actually created and only deleted at exit if it exists.
However, if 'alternative_file' is given and not empty, no temporary filename is created and 'alternative_file' is returned (and not destroyed upon exit). This is useful if you have an optional output file, which may, or may not be requested, but you need its content regardless, e.g. for intermediate plotting with R. Thus you can just call this function to get a file which can be used and gets automatically destroyed if needed.
- Parameters
-
alternative_file | If this string is not empty, no action is taken and it is used as return value |
- Returns
- Full path to a temporary file
static bool validateMatchingFileNames |
( |
const StringList & |
sl1, |
|
|
const StringList & |
sl2, |
|
|
bool |
basename = true , |
|
|
bool |
ignore_extension = true , |
|
|
bool |
strict = false |
|
) |
| |
|
static |
Helper function to test if filenames provided in two StringLists match.
Passing several InputFilesLists is error-prone as users may provide files in a different order. To check for common mistakes this helper function checks:
- if both file lists have the same length (returns false otherwise)
- if the content is the same and provided in exactly the same order (returns false otherwise)
Note: Because workflow systems may assign file names randomly a non-strict comparison mode is enabled by default. Instead of the strict comparison (which returns false if there is a single mismatch), the non-strict comparison mode only returns false if the unique set of filenames match but some positions differ, i.e., only the order has been mixed up.
- Parameters
-
sl1 | First StringList with filenames |
sl2 | Second StringList with filenames |
basename | If set to true, only basenames are compared |
ignore_extension | If set to true, extensions are ignored (e.g., useful to compare spectra filenames to ID filenames) |
strict | If set to true, no mismatches (respecting basename and ignore_extension parameter) are allowed. If set to false, only the order is compared if both share the same filenames. |
- Returns
- False, if both StringLists are different (respecting the parameters)