25 #ifndef SRC_PLATFORM_FILE_H_ 26 #define SRC_PLATFORM_FILE_H_ 28 #include <forward_list> 33 #include <sys/types.h> 44 virtual bool accept(
File& dir,
const string& name) = 0;
53 static const char separatorChar =
'/';
55 File(std::string path ) {
61 if (stat(path.c_str(), &st) == 0) {
62 if (S_ISDIR(st.st_mode)) {
71 if (stat(path.c_str(), &st) == 0) {
72 if ((st.st_mode & S_IFDIR) != 0) {
80 std::string base_filename;
81 std::string::size_type
const o(path.find_last_of(
"/\\"));
82 if (o != std::string::npos) {
83 base_filename = path.substr(o + 1);
86 std::string::size_type
const p(base_filename.find_last_of(
'.'));
87 if (p != std::string::npos) {
88 std::string file_without_extension = base_filename.substr(0, p);
89 return file_without_extension;
95 void listFiles(forward_list<File *>& list,
FilenameFilter& filter) {
98 dpdf = opendir(path.c_str());
100 while ((epdf = readdir(dpdf))) {
101 printf(
"Filename: %s", epdf->d_name);
102 string fname(epdf->d_name);
103 if (filter.accept(*
this, fname)) {
104 File *p_new_file =
new File(epdf->d_name);
105 list.insert_after(list.end(), p_new_file);
119 out(file_path.c_str()) {
122 void println(
const string& line) {