1 #pragma once
2 #ifndef CATA_SRC_FILESYSTEM_H
3 #define CATA_SRC_FILESYSTEM_H
4 
5 #include <string> // IWYU pragma: keep
6 #include <vector>
7 
8 bool assure_dir_exist( const std::string &path );
9 bool dir_exist( const std::string &path );
10 bool file_exist( const std::string &path );
11 // Remove a file, does not remove folders,
12 // returns true on success
13 bool remove_file( const std::string &path );
14 bool remove_directory( const std::string &path );
15 // Rename a file, overriding the target!
16 bool rename_file( const std::string &old_path, const std::string &new_path );
17 
18 std::string read_entire_file( const std::string &path );
19 
20 namespace cata_files
21 {
22 const char *eol();
23 } // namespace cata_files
24 
25 //--------------------------------------------------------------------------------------------------
26 /**
27  * Returns a vector of files or directories matching pattern at @p root_path.
28  *
29  * Searches through the directory tree breadth-first. Directories are searched in lexical
30  * order. Matching files within in each directory are also ordered lexically.
31  *
32  * @param pattern The sub-string to match.
33  * @param root_path The path relative to the current working directory to search; empty means ".".
34  * @param recursive_search Whether to recursively search sub directories.
35  * @param match_extension If true, match pattern at the end of file names. Otherwise, match anywhere
36  *                        in the file name.
37  */
38 std::vector<std::string> get_files_from_path( const std::string &pattern,
39         const std::string &root_path = "", bool recursive_search = false,
40         bool match_extension = false );
41 
42 //--------------------------------------------------------------------------------------------------
43 /**
44  * Returns a vector of directories which contain files matching any of @p patterns.
45  *
46  * @param patterns A vector or patterns to match.
47  * @see get_files_from_path
48  */
49 std::vector<std::string> get_directories_with( const std::vector<std::string> &patterns,
50         const std::string &root_path = "", bool recursive_search = false );
51 
52 std::vector<std::string> get_directories_with( const std::string &pattern,
53         const std::string &root_path = "", bool recursive_search = false );
54 
55 bool copy_file( const std::string &source_path, const std::string &dest_path );
56 
57 /**
58  *  Replace invalid characters in a string with a default character; can be used to ensure that a file name is compliant with most file systems.
59  *  @param file_name Name of the file to check.
60  *  @return A string with all invalid characters replaced with the replacement character, if any change was made.
61  *  @note  The default replacement character is space (0x20) and the invalid characters are "\\/:?\"<>|".
62  */
63 std::string ensure_valid_file_name( const std::string &file_name );
64 
65 #endif // CATA_SRC_FILESYSTEM_H
66