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#include <mutex>
15
16
17namespace OpenMS
18{
19 class Param;
20 class TOPPBase;
21
27 class OPENMS_DLLAPI File
28 {
29public:
34 class OPENMS_DLLAPI TempDir
35 {
36 public:
37
40 TempDir(bool keep_dir = false);
41
44
46 TempDir(const TempDir&) = delete;
47 TempDir& operator=(const TempDir&) = delete;
48 TempDir(TempDir&&) = delete;
50
52 const String& getPath() const;
53
54 private:
57 };
58
64
66 static bool exists(const String& file);
67
69 static bool empty(const String& file);
70
72 static bool executable(const String& file);
73
75 static UInt64 fileSize(const String& file);
76
91 static bool rename(const String& from, const String& to, bool overwrite_existing = true, bool verbose = true);
92
109 enum class CopyOptions {OVERWRITE,SKIP,CANCEL};
110 static bool copyDirRecursively(const QString &from_dir, const QString &to_dir, File::CopyOptions option = CopyOptions::OVERWRITE);
111
113 static bool copy(const String& from, const String& to);
114
120 static bool remove(const String& file);
121
123 static bool removeDirRecursively(const String& dir_name);
124
126 static bool removeDir(const QString& dir_name);
127
130 static bool makeDir(const String& dir_name);
131
134
138 static String basename(const String& file);
139
144 static String path(const String& file);
145
147 static bool readable(const String& file);
148
150 static bool writable(const String& file);
151
153 static bool isDirectory(const String& path);
154
165 static String find(const String& filename, StringList directories = StringList());
166
173 static bool fileList(const String& dir, const String& file_pattern, StringList& output, bool full_path = false);
174
191 static String findDoc(const String& filename);
192
199 static String getUniqueName(bool include_hostname = true);
200
203
206
213
220
227
231 static String findDatabase(const String& db_name);
232
243 static StringList getPathLocations(const String& path = std::getenv("PATH"));
244
258 static bool findExecutable(OpenMS::String& exe_filename);
259
266 static String findSiblingTOPPExecutable(const String& toolName);
267
284 static String getTemporaryFile(const String& alternative_file = "");
285
286
288 {
289 MATCH = 0, // Everything matches perfectly
290 ORDER_MISMATCH = 1, // Same set of files but in wrong order
291 SET_MISMATCH = 2 // Different sets of files (including size mismatch)
292 };
293
310 const StringList& sl2,
311 bool basename = true,
312 bool ignore_extension = true);
313
321 static void download(const std::string& url, const std::string& download_folder);
322
323private:
324
327
329 static bool isOpenMSDataPath_(const String& path);
330
331#ifdef OPENMS_WINDOWSPLATFORM
342 static StringList executableExtensions_(const String& ext = std::getenv("PATHEXT"));
343#endif
344
349 {
350 public:
351 TemporaryFiles_(const TemporaryFiles_&) = delete; // copy is forbidden
356
358 private:
360 std::mutex mtx_;
361 };
362
363
366 };
367}
368
subpage TOPP_TargetedFileConverter Converts targeted feature or consensus feature files subpage TOPP_FileInfo Shows basic information about the file
Definition TOPP.doxygen:44
Class representing a temporary directory.
Definition File.h:35
const String & getPath() const
Return path to temporary folder.
String temp_dir_
Definition File.h:55
~TempDir()
Destroy temporary folder (can be prohibited in Constructor)
TempDir(bool keep_dir=false)
TempDir(const TempDir &)=delete
delete all means to copy or move a TempDir
TempDir(TempDir &&)=delete
TempDir & operator=(const TempDir &)=delete
bool keep_dir_
Definition File.h:56
TempDir & operator=(TempDir &&)=delete
Internal helper class, which holds temporary filenames and deletes these files at program exit.
Definition File.h:349
StringList filenames_
Definition File.h:359
TemporaryFiles_ & operator=(const TemporaryFiles_ &)=delete
String newFile()
create a new filename and queue internally for deletion
TemporaryFiles_(const TemporaryFiles_ &)=delete
std::mutex mtx_
Definition File.h:360
Basic file handling operations.
Definition File.h:28
static bool removeDirRecursively(const String &dir_name)
Removes the subdirectories of the specified directory (absolute path). Returns true if successful.
static String getOpenMSHomePath()
Returns the OpenMS home path (environment variable overwrites the default home path)
static bool exists(const String &file)
Method used to test if a file exists.
static bool copyDirRecursively(const QString &from_dir, const QString &to_dir, File::CopyOptions option=CopyOptions::OVERWRITE)
static String getExecutablePath()
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 unl...
static bool executable(const String &file)
Method used to test if a file is executable.
static String getOpenMSDataPath()
Returns the OpenMS data path (environment variable overwrites the default installation path)
CopyOptions
Copy directory recursively.
Definition File.h:109
static Param getSystemParameterDefaults_()
get defaults for the system's Temp-path, user home directory etc.
static String findDoc(const String &filename)
Resolves a partial file name to a documentation file in the doc-folder.
static String path(const String &file)
static String getUserDirectory()
static String findSiblingTOPPExecutable(const String &toolName)
Searches for an executable with the given name.
static String absolutePath(const String &file)
Replaces the relative path in the argument with the absolute path.
static bool copy(const String &from, const String &to)
Copy a file (if it exists). Returns true if successful.
static String basename(const String &file)
static bool makeDir(const String &dir_name)
static String getUniqueName(bool include_hostname=true)
Returns a string, consisting of date, time, hostname, process id, and a incrementing number....
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 writable(const String &file)
Return true if the file is writable.
static UInt64 fileSize(const String &file)
The filesize in bytes (or -1 on error, e.g. if the file does not exist)
static bool remove(const String &file)
Removes a file (if it exists).
static String getTemporaryFile(const String &alternative_file="")
Obtain a temporary filename, ensuring automatic deletion upon exit.
static String find(const String &filename, StringList directories=StringList())
Looks up the location of the file filename.
MatchingFileListsStatus
Definition File.h:288
static String getTempDirectory()
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).
static bool findExecutable(OpenMS::String &exe_filename)
Searches for an executable with the given name (similar to where (Windows) or which (Linux/MacOS)
static bool readable(const String &file)
Return true if the file exists and is readable.
static bool isOpenMSDataPath_(const String &path)
Check if the given path is a valid OPENMS_DATA_PATH.
static void download(const std::string &url, const std::string &download_folder)
Download file from given URL into a download folder. Returns when done.
static Param getSystemParameters()
static TemporaryFiles_ temporary_files_
private list of temporary filenames, which are deleted upon program exit
Definition File.h:365
static bool isDirectory(const String &path)
Return true if the given path specifies a directory.
static bool removeDir(const QString &dir_name)
Removes the directory and all subdirectories (absolute path).
static bool empty(const String &file)
Return true if the file does not exist or the file is empty.
static bool rename(const String &from, const String &to, bool overwrite_existing=true, bool verbose=true)
Rename a file.
Management and storage of parameters / INI files.
Definition Param.h:46
A more convenient string class.
Definition String.h:34
uint64_t UInt64
Unsigned integer type (64bit)
Definition Types.h:47
std::vector< String > StringList
Vector of String.
Definition ListUtils.h:44
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19