BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
FileSystemUtils.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Util/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_UTIL_FILESYSTEMUTILS_H
21 #define BORNAGAIN_BASE_UTIL_FILESYSTEMUTILS_H
22 
23 #include <string>
24 #include <vector>
25 
26 //! Utility functions to deal with file system.
27 
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 true if extension of path, converted to lower case, matches given reference extension
35 bool hasExtension(const std::string& path, const std::string& ref_extension);
36 
37 //! Returns extension(s) of given filename.
38 //! "/home/user/filename.int" -> ".int", "/home/user/filename.int.gz" -> ".int.gz"
39 std::string extensions(const std::string& path);
40 
41 //! Creates directory in current directory
42 bool createDirectory(const std::string& dir_name);
43 
44 //! Creates directories in current directory for any element of dir_name which doesn't exist.
45 bool createDirectories(const std::string& dir_name);
46 
47 //! Returns filenames of files in directory
48 std::vector<std::string> filesInDirectory(const std::string& dir_name);
49 
50 //! Returns joint path name. Argument path1 may be empty, argument path2 not.
51 std::string jointPath(const std::string& path1, const std::string& path2);
52 
53 //! Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
54 std::string filename(const std::string& path);
55 
56 //! Returns filename without (last) extension.
57 //! "/home/user/filename.int" -> "filename", "/home/user/filename.int.gz" -> "filename.int"
58 std::string stem(const std::string& path);
59 
60 //! Returns filename without extension(s).
61 //! "/home/user/filename.int" -> "filename", "/home/user/filename.int.gz" -> "filename"
62 std::string stem_ext(const std::string& path);
63 
64 //! Returns file names that agree with a regex glob pattern.
65 std::vector<std::string> glob(const std::string& dir, const std::string& pattern);
66 
67 //! Converts utf8 string represented by std::string to utf16 string represented by std::wstring.
68 std::wstring convert_utf8_to_utf16(const std::string& str);
69 
70 //! Returns true if file with given name exists on disk.
71 bool IsFileExists(const std::string& path);
72 
73 } // namespace BaseUtils::Filesystem
74 
75 #endif // BORNAGAIN_BASE_UTIL_FILESYSTEMUTILS_H
76 #endif // USER_API
Utility functions to deal with file system.
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
std::string extensions(const std::string &path)
Returns extension(s) of given filename. "/home/user/filename.int" -> ".int", "/home/user/filename....
std::string jointPath(const std::string &path1, const std::string &path2)
Returns joint path name. Argument path1 may be empty, argument path2 not.
std::string stem_ext(const std::string &path)
Returns filename without extension(s). "/home/user/filename.int" -> "filename", "/home/user/filename....
bool createDirectory(const std::string &dir_name)
Creates directory in current directory.
std::string extension(const std::string &path)
Returns extension of given filename. "/home/user/filename.int" -> ".int", "/home/user/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::vector< std::string > filesInDirectory(const std::string &dir_name)
Returns filenames of files in directory.
std::string stem(const std::string &path)
Returns filename without (last) extension. "/home/user/filename.int" -> "filename",...
bool createDirectories(const std::string &dir_name)
Creates directories in current directory for any element of dir_name which doesn't exist.
std::vector< std::string > glob(const std::string &dir, const std::string &pattern)
Returns file names that agree with a regex glob pattern.
bool hasExtension(const std::string &path, const std::string &ref_extension)
Returns true if extension of path, converted to lower case, matches given reference extension.
bool IsFileExists(const std::string &path)
Returns true if file with given name exists on disk.