1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Chris Bielow $
25
// $Authors: Andreas Bertsch, Chris Bielow, Marc Sturm $
26
// --------------------------------------------------------------------------
29
#ifndef OPENMS_SYSTEM_FILE_H
30
#define OPENMS_SYSTEM_FILE_H
32
#include <OpenMS/DATASTRUCTURES/StringList.h>
33
#include <OpenMS/DATASTRUCTURES/Param.h>
34
#include <OpenMS/config.h>
43
@brief Basic file handling operations.
47
class OPENMS_DLLAPI File
51
friend class TOPPBase;
53
/// Retrieve path of current executable (useful to find other TOPP tools)
54
/// The returned path is either just an EMPTY string if the call to system subroutines failed
55
/// or the complete path including a trailing "/", to enable usage of this function as
56
/// File::getExecutablePath() + "mytool"
57
static String getExecutablePath();
59
/// Method used to test if a @p file exists.
60
static bool exists(const String& file);
62
/// Return true if the file does not exist or the file is empty
63
static bool empty(const String& file);
66
@brief Removes a file (if it exists).
68
@return Returns true if the file was successfully deleted (or if it did not exist).
70
static bool remove(const String& file);
72
/// Removes the specified directory (absolute path). Returns true if successful.
73
static bool removeDirRecursively(const String& dir_name);
75
/// Replaces the relative path in the argument with the absolute path.
76
static String absolutePath(const String& file);
78
/// Returns the basename of the file (without the path).
79
static String basename(const String& file);
81
/// Returns the path of the file (without the file name).
82
static String path(const String& file);
85
Returns the file name without the extension
87
The extension is the suffix of the string upto and including the last dot.
89
If no extension is found, the whole file name is returned
91
static String removeExtension(const String& file);
93
/// Return true if the file exists and is readable
94
static bool readable(const String& file);
96
/// Return true if the file is writable
97
static bool writable(const String& file);
99
/// Return true if the given path specifies a directory
100
static bool isDirectory(const String& path);
103
@brief Looks up the location of the file @p filename
105
The following locations are checked in this order:
106
- the directories in @p directories
107
- the directory contained in the environment variable $OPENMS_DATA_PATH
108
- the 'share/OpenMS/' directory of the OpenMS install directory
110
@exception FileNotFound is thrown, if the file is not found
112
static String find(const String& filename, StringList directories = StringList());
115
@brief Retrieves a list of files matching @p file_pattern in directory @p dir (returns filenames without paths unless @p full_path is true)
117
@return true => there are matching files
119
static bool fileList(const String& dir, const String& file_pattern, StringList& output, bool full_path = false);
121
/// Returns a string, consisting of date, time, hostname, process id, and a incrementing number. This can be used for temporary files.
122
static String getUniqueName();
124
/// Returns the OpenMS data path (environment variable overwrites the default installation path)
125
static String getOpenMSDataPath();
127
/// The current OpenMS temporary data path (for temporary files)
128
static String getTempDirectory();
130
/// The current OpenMS user data path (for result files)
131
static String getUserDirectory();
133
/// get the system's default OpenMS.ini file in the users home directory (<home>/OpenMS/OpenMS.ini)
134
/// or create/repair it if required
135
static Param getSystemParameters();
137
/// uses File::find() to search for a file names @p db_name
138
/// in the 'id_db_dir' param of the OpenMS system parameters
139
/// @exception FileNotFound is thrown, if the file is not found
140
static String findDatabase(const String& db_name);
144
/// get defaults for the system's Temp-path, user home directory etc
145
static Param getSystemParameterDefaults_();
150
#endif // OPENMS_SYSTEM_FILE_H