void getImages(path p){ try{ vector<string> files; // Check path exists if(exists(p)){ if(is_regular_file(p)){ cout << p << " is a regular file, with a size of: " << file_size(p) << endl; cout << "and it's extension is: " << p.extension().string() << endl; }else if(is_directory(p)){ int count = 0; directory_iterator end_itr; for(directory_iterator itr(p); itr != end_itr; ++itr){ files.push_back(itr -> path().filename().string()); cout << "This is the directory status: " << files[count] << endl; count ++; } }else{ cout << "The path is valid but this is not a regular file." << endl; } }else{ cout << "This path is not valid." << endl; } } catch(const filesystem_error& ex){ } }
Source::Source(LanguagePool *languagePool, const path &sourceFilePath) throw(LanguageException, SourceException) { //variable Language *sourceLanguage = nullptr; //vérification de l'existence du fichier if (!exists(sourceFilePath)) { throw SourceException(tr("Le fichier source \"%0\" n'existe pas.", sourceFilePath.native())); } //récupération du langage en fonction de l'extension de la source sourceLanguage = languagePool->getLanguageWithExtension(sourceFilePath.extension().native()); //parsage de la source Source(sourceLanguage, sourceFilePath); }
int main(int argc, char* argv[]) { if (argc == 1) { std::cout << "filtermol2 16_folder 16_id_diff.csv\n"; return 0; } const path subset = argv[1]; const path prop = argv[2]; std::cout << "Reading " << prop << std::endl; vector<string> ids; ids.reserve(5136507); // Number of molecules in 16_id_diff.csv string line; ifstream xls(prop); // getline(xls, line); // Filter out header line. while (getline(xls, line)) { ids.push_back(line); } xls.close(); const path mol2_folder = subset / "mol2"; const string delimiter = "@<TRIPOS>MOLECULE"; vector<string> lines; // Each molecule takes up <= 300 lines. lines.reserve(300); string id; // e.g. ZINC00000007 const directory_iterator end_dir_iter; for (directory_iterator dir_iter(subset); dir_iter != end_dir_iter; ++dir_iter) { if (!is_regular_file(dir_iter->status())) continue; const path mol2_file = dir_iter->path(); // const path mol2_file = subset / "16_p0.0.mol2"; if (mol2_file.extension() != ".mol2") continue; const string slice = mol2_file.stem().string(); std::cout << slice << std::endl; ifstream in(mol2_file); while (getline(in, line)) { if (line == delimiter) { if (!lines.empty()) { if (binary(ids, id.substr(4))) { dump(lines, mol2_folder / (id + ".mol2")); } lines.clear(); } lines.push_back(line); getline(in, id); lines.push_back(id); } else { lines.push_back(line); } } in.close(); if (binary(ids, id)) { dump(lines, mol2_folder / (id + ".mol2")); } lines.clear(); } return 0; }
inline std::string extension(const path & p) { return p.extension().string(); }
path ConcatDumps(const Config& c, path first, path second) { auto output_path = c.dump_dir() / boost::filesystem::unique_path(first.stem().native() + "%%%%-%%%%-%%%%-%%%%" + first.extension().c_str()); if (!fs::exists(first)) { if (!fs::exists(second)) { auto touch = c.ofstream(output_path); return output_path; } fs::copy_file(second, output_path); return output_path; } fs::copy_file(first, output_path); if (!fs::exists(second)) { return output_path; } auto previous = c.ifstream(second); auto append_to = c.ofstream(output_path, std::ios::app); char buffer[4 << 10]; while(!previous.fail()) { previous.read(buffer, sizeof(buffer)); append_to.write(buffer, previous.gcount()); } return output_path; }
// Checks for target file parameters bool Scanner::isDesiredFileType(const path &pathToCheck){ if (!pathToCheck.extension().compare(".jpg")) if ((MIN_SIZE <= file_size(pathToCheck) && file_size(pathToCheck) <= MAX_SIZE)) return true; return false; }