#ifndef __JSYSTEM_JFILEJSYSTEM__ #define __JSYSTEM_JFILEJSYSTEM__ #include #include #include #include namespace JSYSTEM {} namespace JPP { using namespace JSYSTEM; } namespace JSYSTEM { /** * Auxiliary data structure to list files in directory. */ struct ls : public std::vector { /** * Constructor. * * \param dir directory */ ls(const std::string& dir) { DIR* top = opendir(dir.c_str()); if (top != NULL) { for (dirent* i; (i = readdir(top)) != NULL; ) { this->push_back(i->d_name); } closedir(top); } } }; /** * Rename file across file systems. * * \param inputFile input file * \param outputFile input file * \return zero upon success; else non-zero */ inline int rename(const std::string& inputFile, const std::string& outputFile) { using namespace std; ifstream in (inputFile .c_str(), ios::binary); ofstream out(outputFile.c_str(), ios::binary); out << in.rdbuf(); if (out) return remove(inputFile.c_str()); else return -1; } } #endif