Filesystem.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID 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
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file Filesystem.hpp
34 
35  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
36 */
37 
38 
39 
40 #ifndef __OPENFLUID_TOOLS_FILESYSTEM_HPP__
41 #define __OPENFLUID_TOOLS_FILESYSTEM_HPP__
42 
43 
44 #include <string>
45 
46 #include <openfluid/dllexport.hpp>
47 
48 
49 namespace openfluid { namespace tools {
50 
51 
53 {
54 
55  public:
56 
57  /**
58  Returns the name of the file in the given path
59  @code{.cpp}
60  name = openfluid::tools::Filesystem::filename("/tmp/archive.tar.gz")
61  // name = archive.tar.gz
62  @endcode
63  @param[in] Path the given path
64  @return the filename
65  */
66  static std::string filename(const std::string& Path);
67 
68  /**
69  Returns the complete base name of the file in the given path
70  @code{.cpp}
71  name = openfluid::tools::Filesystem::basename("/tmp/archive.tar.gz")
72  // name = archive.tar
73  @endcode
74  @param[in] Path the given path
75  @return the base name of the file
76  */
77  static std::string basename(const std::string& Path);
78 
79  /**
80  Returns the directory name (parent path) of the given path
81  @code{.cpp}
82  name = openfluid::tools::Filesystem::dirname("/tmp/archive.tar.gz")
83  // name = /tmp
84  @endcode
85  @param[in] Path the given path
86  @return the directory name
87  */
88  static std::string dirname(const std::string& Path);
89 
90  /**
91  Returns the extension of the file of the given path
92  @code{.cpp}
93  name = openfluid::tools::Filesystem::extension("/tmp/archive.tar.gz")
94  // name = gz
95  @endcode
96  @param[in] Path the given path
97  @return the extension
98  */
99  static std::string extension(const std::string& Path);
100 
101  /**
102  Returns the current application path
103  @return the current path
104  */
105  static std::string currentPath();
106 
107  /**
108  Returns true if the given path is a directory
109  @param[in] Path the given path
110  @return true or false
111  */
112  static bool isDirectory(const std::string& Path);
113 
114  /**
115  Returns true if the given path is a file or a valid symbolic link
116  @param[in] Path the given path
117  @return true or false
118  */
119  static bool isFile(const std::string& Path);
120 
121  /**
122  Creates the directory of the given path. It creates all parent directories necessary to create the directory.
123  If the directory already exists, it does nothing.
124  @param[in] Path the given path
125  @return true if the directory was successfully created, false otherwise
126  */
127  static bool makeDirectory(const std::string& Path);
128 
129  /**
130  Removes the directory of the given path. It recursively deletes all contents of the directory.
131  @param[in] Path the given path
132  @return true if the directory was successfully deleted, false otherwise
133  */
134  static bool removeDirectory(const std::string& Path);
135 
136  /**
137  Creates a unique subdirectory in the given path, using the given subdirectory name as a prefix.
138  If the subdirectory already exists, it adds an incremental suffix to the subdirectory name.
139  It creates all parent directories necessary to create the subdirectory.
140  @param[in] Path the given path
141  @param[in] SubdirName the given path
142  @return the full path of the created unique subdirectory
143  */
144  static std::string makeUniqueSubdirectory(const std::string& Path, const std::string& SubdirName);
145 
146  /**
147  Creates a unique file in the given path, using the given File name and extension as prefix and suffix.
148  If the file already exists, it adds an incremental part to the file name.
149  If the Path does not exists, it creates all needed parent directories.
150  @param[in] Path the given path for the file
151  @param[in] FileName the file name used to make a unique one
152  @return the full path of the created unique file
153  */
154  static std::string makeUniqueFile(const std::string& Path, const std::string& FileName);
155 
156 
157  /**
158  Removes the file of the given path.
159  @param[in] Path the given path
160  @return true if the file was successfully deleted, false otherwise
161  */
162  static bool removeFile(const std::string& Path);
163 
164  /**
165  Copies a file from source to destination.
166  @param[in] SrcPath the source path
167  @param[in] DestPath the destination path
168  @return true if the file was successfully copied, false otherwise
169  */
170  static bool copyFile(const std::string& SrcPath, const std::string& DestPath);
171 
172  /**
173  Recursively copies a directory from source to destination.
174  @param[in] SrcPath the source path
175  @param[in] DestPath the destination path
176  @param[in] DontCopyDotDirs if set to true, it ignores the directories beginning with a dot ('.').
177  Default is false
178  @return true if the directory was successfully copied, false otherwise
179  */
180  static bool copyDirectory(const std::string& SrcPath, const std::string& DestPath,
181  const bool DontCopyDotDirs = false);
182 
183 };
184 
185 } } // namespaces
186 
187 
188 
189 #endif /* __OPENFLUID_TOOLS_FILESYSTEM_HPP__ */
Definition: ApplicationException.hpp:47
Definition: Filesystem.hpp:52
#define OPENFLUID_API
Definition: dllexport.hpp:87