BornAgain  1.18.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 scattering at grazing incidence
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 #ifndef BORNAGAIN_BASE_UTILS_FILESYSTEMUTILS_H
16 #define BORNAGAIN_BASE_UTILS_FILESYSTEMUTILS_H
17 
18 #include <string>
19 #include <vector>
20 
21 //! Utility functions to deal with file system.
22 
23 namespace FileSystemUtils
24 {
25 
26 //! Returns extension of given filename.
27 //! "/home/user/filename.int" -> ".int", "/home/user/filename.int.gz" -> ".gz"
28 std::string extension(const std::string& path);
29 
30 //! Returns extension(s) of given filename.
31 //! "/home/user/filename.int" -> ".int", "/home/user/filename.int.gz" -> ".int.gz"
32 std::string extensions(const std::string& path);
33 
34 //! Creates directory in current directory
35 bool createDirectory(const std::string& dir_name);
36 
37 //! Creates directories in current directory for any element of dir_name which doesn't exist.
38 bool createDirectories(const std::string& dir_name);
39 
40 //! Returns filenames of files in directory
41 std::vector<std::string> filesInDirectory(const std::string& dir_name);
42 
43 //! Returns joint path name.
44 std::string jointPath(const std::string& spath1, const std::string& spath2);
45 
46 //! Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
47 std::string filename(const std::string& path);
48 
49 //! Returns filename without extension.
50 //! "/home/user/filename.int" -> "filename", "/home/user/filename.int.gz" -> "filename.int"
51 std::string stem(const std::string& path);
52 
53 //! Returns filename without extension(s).
54 //! "/home/user/filename.int" -> "filename", "/home/user/filename.int.gz" -> "filename"
55 std::string stem_ext(const std::string& path);
56 
57 //! Returns file names that agree with a regex glob pattern.
58 std::vector<std::string> glob(const std::string& dir, const std::string& pattern);
59 
60 //! Converts utf8 string represented by std::string to utf16 string represented by std::wstring.
61 std::wstring convert_utf8_to_utf16(const std::string& str);
62 
63 //! Returns true if file with given name exists on disk.
64 bool IsFileExists(const std::string& str);
65 
66 } // namespace FileSystemUtils
67 
68 #endif // BORNAGAIN_BASE_UTILS_FILESYSTEMUTILS_H
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).
std::string extension(const std::string &path)
Returns extension of given filename.
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.
bool IsFileExists(const std::string &str)
Returns true if file with given name exists on disk.
std::string stem(const std::string &path)
Returns filename without extension.
std::vector< std::string > filesInDirectory(const std::string &dir_name)
Returns filenames of files in directory.
std::string jointPath(const std::string &spath1, const std::string &spath2)
Returns joint path name.
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.