ModErn Text Analysis
META Enumerates Textual Applications
filesystem.h
Go to the documentation of this file.
1 
10 #ifndef META_FILESYSTEM_H_
11 #define META_FILESYSTEM_H_
12 
13 #include <cstdint>
14 #include <stdexcept>
15 #include <string>
16 
17 #include "meta/config.h"
18 
19 #if META_HAS_EXPERIMENTAL_FILESYSTEM
20 #include <experimental/filesystem>
21 #endif
22 
23 namespace meta
24 {
25 namespace filesystem
26 {
27 
28 #if META_HAS_EXPERIMENTAL_FILESYSTEM == 0
29 class filesystem_exception : public std::runtime_error
30 {
31  public:
32  using std::runtime_error::runtime_error;
33 };
34 #else
35 using filesystem_exception = std::experimental::filesystem::filesystem_error;
36 #endif
37 
42 bool delete_file(const std::string& filename);
43 
49 void rename_file(const std::string& old_name, const std::string& new_name);
50 
56 bool make_directory(const std::string& dir_name);
57 
63 bool make_directories(const std::string& path);
64 
69 bool file_exists(const std::string& filename);
70 
75 bool exists(const std::string& path);
76 
82 uint64_t file_size(const std::string& filename);
83 
90 bool copy_file(const std::string& source, const std::string& dest);
91 
96 std::string file_text(const std::string& in_name);
97 
104 uint64_t num_lines(const std::string& filename, char delimiter = '\n');
105 
113 std::uintmax_t remove_all(const std::string& path);
114 }
115 }
116 #endif
bool delete_file(const std::string &filename)
Deletes the given file.
Definition: filesystem.cpp:47
bool copy_file(const std::string &source, const std::string &dest)
Copies a file source to file dest.
Definition: filesystem.cpp:231
void rename_file(const std::string &old_name, const std::string &new_name)
Renames the given file.
Definition: filesystem.cpp:52
bool file_exists(const std::string &filename)
Definition: filesystem.cpp:68
bool make_directory(const std::string &dir_name)
Attempts to create the directory.
Definition: filesystem.cpp:58
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retrieval, data mining, and other applications of text processing.
Definition: analyzer.h:25
uint64_t file_size(const std::string &filename)
Calculates a file&#39;s size in bytes with support for files over 4GB.
Definition: filesystem.cpp:78
bool exists(const std::string &path)
Definition: filesystem.cpp:73
Definition: filesystem.h:29
std::uintmax_t remove_all(const std::string &path)
Removes the contents of path (if it is a directory) and the contents of all of its subdirectories...
Definition: filesystem.cpp:166
std::string file_text(const std::string &in_name)
Definition: filesystem.cpp:267
uint64_t num_lines(const std::string &filename, char delimiter='\n')
Definition: filesystem.cpp:275
bool make_directories(const std::string &path)
Attempts to create the directory and any other directories in the path.
Definition: filesystem.cpp:63