1 #include "directory.hpp"
4 #include <boost/filesystem.hpp>
6 #ifdef BOOST_FILESYSTEM3
7 namespace boost_fs
= boost::filesystem3
;
9 namespace boost_fs
= boost::filesystem
;
12 std::set
<std::string
> enumerate_directory(const std::string
& dir
, const std::string
& match
)
14 std::set
<std::string
> x
;
17 d
= opendir(dir
.c_str());
19 (stringfmt() << "Can't read directory '" << dir
<< "'").throwex();
22 while((d2
= readdir(d
)))
23 if(regex_match(match
, d2
->d_name
) && strcmp(d2
->d_name
, ".") && strcmp(d2
->d_name
, ".."))
24 x
.insert(dir
+ "/" + d2
->d_name
);
29 std::string
get_absolute_path(const std::string
& relative
)
31 return boost_fs::absolute(boost_fs::path(relative
)).string();
34 uintmax_t file_get_size(const std::string
& path
)
36 return boost_fs::file_size(boost_fs::path(path
));
39 time_t file_get_mtime(const std::string
& path
)
41 boost::system::error_code ec
;
42 time_t t
= boost_fs::last_write_time(boost_fs::path(path
), ec
);
48 bool file_exists(const std::string
& filename
)
50 boost::system::error_code ec
;
51 return boost_fs::exists(boost_fs::path(filename
), ec
);
54 bool file_is_regular(const std::string
& filename
)
56 boost::system::error_code ec
;
57 boost_fs::file_status stat
= status(boost_fs::path(filename
), ec
);
58 bool e
= is_regular_file(stat
);
62 bool file_is_directory(const std::string
& filename
)
64 boost_fs::path
p(filename
);
65 return boost_fs::is_directory(p
);
68 bool ensure_directory_exists(const std::string
& path
)
70 boost_fs::path
p(path
);
71 return boost_fs::create_directories(p
) || boost_fs::is_directory(p
);