All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <openfluid/dllexport.hpp>
45 
46 
47 namespace openfluid { namespace tools {
48 
49 
51 {
52 
53  public:
54 
55  /**
56  Returns the name of the file in the given path
57  @code{.cpp}
58  name = openfluid::tools::Filesystem::filename("/tmp/archive.tar.gz")
59  // name = archive.tar.gz
60  @endcode
61  @param[in] Path the given path
62  @return the filename
63  */
64  static std::string filename(const std::string& Path);
65 
66  /**
67  Returns the complete base name of the file in the given path
68  @code{.cpp}
69  name = openfluid::tools::Filesystem::basename("/tmp/archive.tar.gz")
70  // name = archive.tar
71  @endcode
72  @param[in] Path the given path
73  @return the base name of the file
74  */
75  static std::string basename(const std::string& Path);
76 
77  /**
78  Returns the directory name (parent path) of the given path
79  @code{.cpp}
80  name = openfluid::tools::Filesystem::dirname("/tmp/archive.tar.gz")
81  // name = /tmp
82  @endcode
83  @param[in] Path the given path
84  @return the directory name
85  */
86  static std::string dirname(const std::string& Path);
87 
88  /**
89  Returns the extension of the file of the given path
90  @code{.cpp}
91  name = openfluid::tools::Filesystem::extension("/tmp/archive.tar.gz")
92  // name = gz
93  @endcode
94  @param[in] Path the given path
95  @return the extension
96  */
97  static std::string extension(const std::string& Path);
98 
99  /**
100  Returns the current application path
101  @return the current path
102  */
103  static std::string currentPath();
104 
105  /**
106  Returns true if the given path is a directory
107  @param[in] Path the given path
108  @return true or false
109  */
110  static bool isDirectory(const std::string& Path);
111 
112  /**
113  Returns true if the given path is a file or a valid symbolic link
114  @param[in] Path the given path
115  @return true or false
116  */
117  static bool isFile(const std::string& Path);
118 
119  /**
120  Creates the directory of the given path. It creates all parent directories necessary to create the directory.
121  If the directory already exists, it does nothing.
122  @param[in] Path the given path
123  @return true if the directory was successfully created, false otherwise
124  */
125  static bool makeDirectory(const std::string& Path);
126 
127  /**
128  Removes the directory of the given path. It recursively deletes all contents of the directory.
129  @param[in] Path the given path
130  @return true if the directory was successfully deleted, false otherwise
131  */
132  static bool removeDirectory(const std::string& Path);
133 
134  /**
135  Removes the file of the given path.
136  @param[in] Path the given path
137  @return true if the file was successfully deleted, false otherwise
138  */
139  static bool removeFile(const std::string& Path);
140 
141  /**
142  Copies a file from source to destination.
143  @param[in] SrcPath the source path
144  @param[in] DestPath the destination path
145  @return true if the file was successfully copied, false otherwise
146  */
147  static bool copyFile(const std::string& SrcPath, const std::string& DestPath);
148 
149  /**
150  Recursively copies a directory from source to destination.
151  @param[in] SrcPath the source path
152  @param[in] DestPath the destination path
153  @param[in] DontCopyDotDirs if set to true, it ignores the directories beginning with a dot ('.').
154  Default is false
155  @return true if the directory was successfully copied, false otherwise
156  */
157  static bool copyDirectory(const std::string& SrcPath, const std::string& DestPath,
158  const bool DontCopyDotDirs = false);
159 
160 };
161 
162 } } // namespaces
163 
164 
165 
166 #endif /* __OPENFLUID_TOOLS_FILESYSTEM_HPP__ */
Definition: Filesystem.hpp:50
#define OPENFLUID_API
Definition: dllexport.hpp:87