1 #ifndef ROSE_FileSystem_H
2 #define ROSE_FileSystem_H
4 #include <boost/filesystem.hpp>
5 #include <boost/regex.hpp>
12 namespace FileSystem {
18 typedef boost::filesystem::path
Path;
27 ROSE_UTIL_API
bool isExisting(
const Path &path);
30 ROSE_UTIL_API
bool isFile(
const Path &path);
54 const boost::regex &re_;
57 bool operator()(
const Path &path);
81 ROSE_UTIL_API Path
makeRelative(
const Path &path,
const Path &root = boost::filesystem::current_path());
87 ROSE_UTIL_API Path
makeAbsolute(
const Path &path,
const Path &root = boost::filesystem::current_path());
99 template<
class Select>
100 std::vector<Path>
findNames(
const Path &root, Select select) {
101 std::vector<Path> matching;
104 if (select(iter->path()))
105 matching.push_back(iter->path());
108 std::sort(matching.begin(), matching.end());
112 ROSE_UTIL_API std::vector<Path>
findNames(
const Path &root);
128 template<
class Select,
class Descend>
130 std::vector<Path> matching;
131 RecursiveDirectoryIterator end;
132 for (RecursiveDirectoryIterator dentry(root); dentry!=end; ++dentry) {
133 if (select(dentry->path()))
134 matching.push_back(dentry->path());
135 if (!descend(dentry->path()))
138 std::sort(matching.begin(), matching.end());
142 template<
class Select>
153 ROSE_UTIL_API
void copyFile(
const Path &sourceFileName,
const Path &destinationFileName);
165 ROSE_UTIL_API
void copyFiles(
const std::vector<Path> &files,
const Path &root,
const Path &destinationDirectory);
172 template<
class Select,
class Descend>
175 files.erase(files.begin(), std::remove_if(files.begin(), files.end(),
isFile));
185 ROSE_UTIL_API std::string
toString(
const Path&);
Predicate returning true for matching names.
ROSE_UTIL_API bool isExisting(const Path &path)
Predicate returning true if path exists.
std::vector< Path > findNamesRecursively(const Path &root, Select select, Descend descend)
Recursive list of names satisfying predicate.
ROSE_UTIL_API Path makeNormal(const Path &)
Normalize a path name.
boost::filesystem::path Path
Name of entities in a filesystem.
void copyFilesRecursively(const Path &root, const Path &destination, Select select, Descend descend)
Recursively copy files.
ROSE_UTIL_API void copyFile(const Path &sourceFileName, const Path &destinationFileName)
Copy a file.
ROSE_UTIL_API Path createTemporaryDirectory()
Create a temporary directory.
boost::filesystem::recursive_directory_iterator RecursiveDirectoryIterator
Iterate recursively into subdirectories.
ROSE_UTIL_API bool isDirectory(const Path &path)
Predicate returning true for existing directories.
Main namespace for the ROSE library.
const char * tempNamePattern
Pattern to use when creating temporary files.
boost::filesystem::directory_iterator DirectoryIterator
Iterate over directory contents non-recursively.
ROSE_UTIL_API std::string toString(const Path &)
Convert a path to a string.
ROSE_UTIL_API void copyFiles(const std::vector< Path > &files, const Path &root, const Path &destinationDirectory)
Copy files from one directory to another.
ROSE_UTIL_API bool isSymbolicLink(const Path &path)
Predicate returning true for existing symbolic links.
ROSE_UTIL_API bool isFile(const Path &path)
Predicate returning true for existing regular files.
std::vector< Path > findNames(const Path &root, Select select)
Entries within a directory.
ROSE_UTIL_API std::vector< Path > findRoseFilesRecursively(const Path &root)
Return a list of all rose_* files.
ROSE_UTIL_API bool isNotSymbolicLink(const Path &path)
Predicate returning inverse of isSymbolicLink.
ROSE_UTIL_API Path makeAbsolute(const Path &path, const Path &root=boost::filesystem::current_path())
Make path absolute.
ROSE_UTIL_API Path makeRelative(const Path &path, const Path &root=boost::filesystem::current_path())
Make path relative.