OpenMS
Loading...
Searching...
No Matches
File.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Chris Bielow $
6// $Authors: Andreas Bertsch, Chris Bielow, Marc Sturm $
7// --------------------------------------------------------------------------
8
9#pragma once
10
12#include <OpenMS/config.h>
13#include <cstdlib>
14
15
16namespace OpenMS
17{
18 class TOPPBase;
19
25 class OPENMS_DLLAPI File
26 {
27public:
32 static std::string getExecutablePath();
33
35 static bool exists(const std::string& file);
36
38 static bool empty(const std::string& file);
39
41 static bool executable(const std::string& file);
42
44 static UInt64 fileSize(const std::string& file);
45
55 static Int64 getModificationTime(const std::string& file);
56
71 static bool rename(const std::string& from, const std::string& to, bool overwrite_existing = true, bool verbose = true);
72
89 enum class CopyOptions {OVERWRITE,SKIP,CANCEL};
90 static bool copyDirRecursively(const std::string& from_dir, const std::string& to_dir, File::CopyOptions option = CopyOptions::OVERWRITE);
91
93 static bool copy(const std::string& from, const std::string& to);
94
100 static bool remove(const std::string& file);
101
103 static bool removeDirRecursively(const std::string& dir_name);
104
106 static bool removeDir(const std::string& dir_name);
107
110 static bool makeDir(const std::string& dir_name);
111
113 static std::string absolutePath(const std::string& file);
114
125 static std::string toFileURI(const std::string& file);
126
130 static std::string basename(const std::string& file);
131
137 static std::string stemName(const std::string& file);
138
143 static std::string extension(const std::string& file);
144
147 static StringList listDirectories(const std::string& dir);
148
153 static std::string path(const std::string& file);
154
156 static bool readable(const std::string& file);
157
159 static bool writable(const std::string& file);
160
162 static bool isDirectory(const std::string& path);
163
174 static std::string find(const std::string& filename, StringList directories = StringList());
175
182 static bool fileList(const std::string& dir, const std::string& file_pattern, StringList& output, bool full_path = false);
183
200 static std::string findDoc(const std::string& filename);
201
208 static std::string getUniqueName(bool include_hostname = true);
209
212 static std::string getOpenMSDataPath();
213
219 static const std::string& getOpenMSDataPathSource();
220
232
240 static StringList getPathLocations(const std::string& path);
241
255 static bool findExecutable(std::string& exe_filename);
256
263 static std::string findSiblingTOPPExecutable(const std::string& toolName);
264
266 {
267 MATCH = 0, // Everything matches perfectly
268 ORDER_MISMATCH = 1, // Same set of files but in wrong order
269 SET_MISMATCH = 2 // Different sets of files (including size mismatch)
270 };
271
288 const StringList& sl2,
289 bool basename = true,
290 bool ignore_extension = true);
291
292private:
293
295 static bool isOpenMSDataPath_(const std::string& path);
296
299 {
300 std::string path;
301 std::string source;
302 };
303
306
307#ifdef OPENMS_WINDOWSPLATFORM
317 static StringList executableExtensions_();
318
326 static StringList executableExtensions_(const std::string& ext);
327#endif
328 };
329}
Basic file handling operations.
Definition File.h:26
static std::string findDoc(const std::string &filename)
Resolves a partial file name to a documentation file in the doc-folder.
static std::string findSiblingTOPPExecutable(const std::string &toolName)
Searches for an executable with the given name.
static std::string find(const std::string &filename, StringList directories=StringList())
Looks up the location of the file filename.
std::string source
human-readable origin, e.g. "the OPENMS_DATA_PATH environment variable"
Definition File.h:301
static bool executable(const std::string &file)
Method used to test if a file is executable.
static bool removeDir(const std::string &dir_name)
Removes a directory and all its contents (absolute path). Returns true if successful.
static bool writable(const std::string &file)
Return true if the file is writable.
CopyOptions
Copy directory recursively.
Definition File.h:89
static StringList listDirectories(const std::string &dir)
static bool remove(const std::string &file)
Removes a file (if it exists).
std::string path
the resolved shared-data directory
Definition File.h:300
static std::string toFileURI(const std::string &file)
Convert a local path to an absolute file URI.
static std::string basename(const std::string &file)
static bool fileList(const std::string &dir, const std::string &file_pattern, StringList &output, bool full_path=false)
Retrieves a list of files matching file_pattern in directory dir (returns filenames without paths unl...
static StringList getPathLocations()
Extract list of directories from a concatenated string (usually $PATH).
static MatchingFileListsStatus validateMatchingFileNames(const StringList &sl1, const StringList &sl2, bool basename=true, bool ignore_extension=true)
Helper function to test if filenames provided in two StringLists match.
static bool empty(const std::string &file)
Return true if the file does not exist or the file is empty.
static bool readable(const std::string &file)
Return true if the file exists and is readable.
static std::string extension(const std::string &file)
static UInt64 fileSize(const std::string &file)
The filesize in bytes (or -1 on error, e.g. if the file does not exist)
static bool makeDir(const std::string &dir_name)
static std::string absolutePath(const std::string &file)
Replaces the relative path in the argument with the absolute path.
static std::string getUniqueName(bool include_hostname=true)
Returns a string, consisting of date, time, hostname, process id, and a incrementing number....
static std::string path(const std::string &file)
static const std::string & getOpenMSDataPathSource()
Returns a human-readable description of where getOpenMSDataPath() resolved from.
static bool findExecutable(std::string &exe_filename)
Searches for an executable with the given name (similar to where (Windows) or which (Linux/MacOS)
static bool isOpenMSDataPath_(const std::string &path)
Check if the given path is a valid OPENMS_DATA_PATH.
MatchingFileListsStatus
Definition File.h:266
static bool removeDirRecursively(const std::string &dir_name)
Removes a directory and all its contents recursively (absolute path). Returns true if successful.
static std::string stemName(const std::string &file)
static std::string getExecutablePath()
static bool copyDirRecursively(const std::string &from_dir, const std::string &to_dir, File::CopyOptions option=CopyOptions::OVERWRITE)
static bool exists(const std::string &file)
Method used to test if a file exists.
static bool copy(const std::string &from, const std::string &to)
Copy a file (if it exists). Returns true if successful.
static std::string getOpenMSDataPath()
static const OpenMSDataPath_ & resolveOpenMSDataPath_()
Resolve (once, thread-safe) and return the OpenMS data path together with where it was found.
static Int64 getModificationTime(const std::string &file)
Last modification time of file, in seconds since the Unix epoch (or -1 on error).
static bool isDirectory(const std::string &path)
Return true if the given path specifies a directory.
static StringList getPathLocations(const std::string &path)
Extract list of directories from an explicit concatenated path string.
static bool rename(const std::string &from, const std::string &to, bool overwrite_existing=true, bool verbose=true)
Rename a file.
Bundles the resolved OpenMS data path with a human-readable description of where it was found (for di...
Definition File.h:299
int64_t Int64
Signed integer type (64bit)
Definition Types.h:40
uint64_t UInt64
Unsigned integer type (64bit)
Definition Types.h:47
std::vector< std::string > StringList
Vector of String.
Definition TypeAliases.h:39
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19