BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FileSystemUtils.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Utils/FileSystemUtils.h
6 //! @brief Defines namespace FileSystemUtils.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_BASE_UTILS_FILESYSTEMUTILS_H
21 #define BORNAGAIN_BASE_UTILS_FILESYSTEMUTILS_H
22 
23 #include <string>
24 #include <vector>
25 
26 //! Utility functions to deal with file system.
27 
28 namespace FileSystemUtils {
29 
30 //! Returns extension of given filename.
31 //! "/home/user/filename.int" -> ".int", "/home/user/filename.int.gz" -> ".gz"
32 std::string extension(const std::string& path);
33 
34 //! Returns extension(s) of given filename.
35 //! "/home/user/filename.int" -> ".int", "/home/user/filename.int.gz" -> ".int.gz"
36 std::string extensions(const std::string& path);
37 
38 //! Creates directory in current directory
39 bool createDirectory(const std::string& dir_name);
40 
41 //! Creates directories in current directory for any element of dir_name which doesn't exist.
42 bool createDirectories(const std::string& dir_name);
43 
44 //! Returns filenames of files in directory
45 std::vector<std::string> filesInDirectory(const std::string& dir_name);
46 
47 //! Returns joint path name.
48 std::string jointPath(const std::string& path1, const std::string& path2);
49 
50 //! Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
51 std::string filename(const std::string& path);
52 
53 //! Returns filename without (last) extension.
54 //! "/home/user/filename.int" -> "filename", "/home/user/filename.int.gz" -> "filename.int"
55 std::string stem(const std::string& path);
56 
57 //! Returns filename without extension(s).
58 //! "/home/user/filename.int" -> "filename", "/home/user/filename.int.gz" -> "filename"
59 std::string stem_ext(const std::string& path);
60 
61 //! Returns file names that agree with a regex glob pattern.
62 std::vector<std::string> glob(const std::string& dir, const std::string& pattern);
63 
64 //! Converts utf8 string represented by std::string to utf16 string represented by std::wstring.
65 std::wstring convert_utf8_to_utf16(const std::string& str);
66 
67 //! Returns true if file with given name exists on disk.
68 bool IsFileExists(const std::string& path);
69 
70 } // namespace FileSystemUtils
71 
72 #endif // BORNAGAIN_BASE_UTILS_FILESYSTEMUTILS_H
73 #endif // USER_API
Utility functions to deal with file system.
std::string extensions(const std::string &path)
Returns extension(s) of given filename.
std::wstring convert_utf8_to_utf16(const std::string &str)
Converts utf8 string represented by std::string to utf16 string represented by std::wstring.
std::string stem_ext(const std::string &path)
Returns filename without extension(s).
bool IsFileExists(const std::string &path)
Returns true if file with given name exists on disk.
std::string extension(const std::string &path)
Returns extension of given filename.
std::string jointPath(const std::string &path1, const std::string &path2)
Returns joint path name.
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
std::vector< std::string > glob(const std::string &dir, const std::string &pattern)
Returns file names that agree with a regex glob pattern.
std::string stem(const std::string &path)
Returns filename without (last) extension.
std::vector< std::string > filesInDirectory(const std::string &dir_name)
Returns filenames of files in directory.
bool createDirectories(const std::string &dir_name)
Creates directories in current directory for any element of dir_name which doesn't exist.
bool createDirectory(const std::string &dir_name)
Creates directory in current directory.