ROSE 0.11.145.192
|
Functions for operating on files in a filesystem.
Classes | |
class | baseNameMatches |
Predicate returning true for matching names. More... | |
Typedefs | |
typedef boost::filesystem::path | Path |
Name of entities in a filesystem. | |
typedef boost::filesystem::directory_iterator | DirectoryIterator |
Iterate over directory contents non-recursively. | |
typedef boost::filesystem::recursive_directory_iterator | RecursiveDirectoryIterator |
Iterate recursively into subdirectories. | |
Functions | |
ROSE_UTIL_API bool | isExisting (const Path &path) |
Predicate returning true if path exists. | |
ROSE_UTIL_API bool | isFile (const Path &path) |
Predicate returning true for existing regular files. | |
ROSE_UTIL_API bool | isDirectory (const Path &path) |
Predicate returning true for existing directories. | |
ROSE_UTIL_API bool | isSymbolicLink (const Path &path) |
Predicate returning true for existing symbolic links. | |
ROSE_UTIL_API bool | isNotSymbolicLink (const Path &path) |
Predicate returning inverse of isSymbolicLink. | |
ROSE_UTIL_API Path | createTemporaryDirectory () |
Create a temporary directory. | |
ROSE_UTIL_API Path | makeNormal (const Path &) |
Normalize a path name. | |
ROSE_UTIL_API Path | makeRelative (const Path &path, const Path &root=boost::filesystem::current_path()) |
Make path relative. | |
ROSE_UTIL_API Path | makeAbsolute (const Path &path, const Path &root=boost::filesystem::current_path()) |
Make path absolute. | |
ROSE_UTIL_API void | copyFile (const Path &sourceFileName, const Path &destinationFileName) |
Copy a file. | |
ROSE_UTIL_API void | copyFiles (const std::vector< Path > &files, const Path &root, const Path &destinationDirectory) |
Copy files from one directory to another. | |
template<class Select , class Descend > | |
void | copyFilesRecursively (const Path &root, const Path &destination, Select select, Descend descend) |
Recursively copy files. | |
ROSE_UTIL_API std::vector< Path > | findRoseFilesRecursively (const Path &root) |
Return a list of all rose_* files. | |
ROSE_UTIL_API std::string | toString (const Path &) |
Convert a path to a string. | |
template<class Container > | |
Container | readFile (const boost::filesystem::path &fileName, std::ios_base::openmode openMode=std::ios_base::in|std::ios_base::binary) |
Load an entire file into an STL container. | |
template<class Container > | |
void | writeFile (const boost::filesystem::path &fileName, const Container &data, std::ios_base::openmode openMode=std::ios_base::out|std::ios_base::binary) |
Write a container to a file. | |
template<class Select > | |
std::vector< Path > | findNames (const Path &root, Select select) |
Entries within a directory. | |
ROSE_UTIL_API std::vector< Path > | findNames (const Path &root) |
Entries within a directory. | |
template<class Select , class Descend > | |
std::vector< Path > | findNamesRecursively (const Path &root, Select select, Descend descend) |
Recursive list of names satisfying predicate. | |
template<class Select > | |
std::vector< Path > | findNamesRecursively (const Path &root, Select select) |
Recursive list of names satisfying predicate. | |
ROSE_UTIL_API std::vector< Path > | findNamesRecursively (const Path &root) |
Recursive list of names satisfying predicate. | |
Variables | |
const char * | tempNamePattern |
Pattern to use when creating temporary files. | |
typedef boost::filesystem::path Rose::FileSystem::Path |
Name of entities in a filesystem.
Definition at line 24 of file Rose/FileSystem.h.
typedef boost::filesystem::directory_iterator Rose::FileSystem::DirectoryIterator |
Iterate over directory contents non-recursively.
Definition at line 27 of file Rose/FileSystem.h.
typedef boost::filesystem::recursive_directory_iterator Rose::FileSystem::RecursiveDirectoryIterator |
Iterate recursively into subdirectories.
Definition at line 30 of file Rose/FileSystem.h.
ROSE_UTIL_API Path Rose::FileSystem::createTemporaryDirectory | ( | ) |
Create a temporary directory.
The temporary directory is created as a subdirectory of the directory which is suitable for temporary files under the conventions of the operating system. The specifics of how this path is determined are implementation defined (see boost::filesystem::temp_directory_path
). The created subdirectory has a name of the form "rose-%%%%%%%%-%%%%%%%%" where each "%" is a random hexadecimal digit. Returns the path to this directory.
Normalize a path name.
Normalizes a path by removing "." and ".." components to the extent which is possible.
For instance, a name like "/foo/bar/../baz" will become "/foo/baz" and the name "/foo/./baz" will become "/foo/baz". However, the names "/../foo" and "./foo" cannot be changed because removing the ".." in the first case would place it in a different directory if the name were appended to another name, and in the second case it would convert a relative name to an absolute name.
ROSE_UTIL_API Path Rose::FileSystem::makeRelative | ( | const Path & | path, |
const Path & | root = boost::filesystem::current_path() |
||
) |
Make path relative.
Makes the specified path relative to another path or the current working directory.
ROSE_UTIL_API Path Rose::FileSystem::makeAbsolute | ( | const Path & | path, |
const Path & | root = boost::filesystem::current_path() |
||
) |
Make path absolute.
Makes the specified path an absolute path if it is a relative path. If relative, then assume root
is what the path is relative to.
std::vector< Path > Rose::FileSystem::findNames | ( | const Path & | root, |
Select | select | ||
) |
Entries within a directory.
Returns a list of entries in a directory–the contents of a directory–without recursing into subdirectories. The return value is a sorted list of paths, each of which contains root
as a prefix. If a select
predicate is supplied then only paths for which the predicate returns true become part of the return value. The predicate is called with the path that would become part of the return value. The root
itself is never returned and never tested by the predicate.
If select
is not specified then all entries are returned.
Definition at line 106 of file Rose/FileSystem.h.
References isDirectory().
Entries within a directory.
Returns a list of entries in a directory–the contents of a directory–without recursing into subdirectories. The return value is a sorted list of paths, each of which contains root
as a prefix. If a select
predicate is supplied then only paths for which the predicate returns true become part of the return value. The predicate is called with the path that would become part of the return value. The root
itself is never returned and never tested by the predicate.
If select
is not specified then all entries are returned.
std::vector< Path > Rose::FileSystem::findNamesRecursively | ( | const Path & | root, |
Select | select, | ||
Descend | descend | ||
) |
Recursive list of names satisfying predicate.
Returns a list of entries in a directory and all subdirectories recursively. The return value is a sorted list of paths, each of which contains root
as a prefix. If a select
predicate is supplied then only paths for which the predicate returns true become part of the return value. If a descend
predicate is supplied then this algorithm only recurses into subdirectories for which descend
returns true. The predicates are called with the path that would become part of the return value. The root
itself is never returned and never tested by the select
or descend
predicates.
If select
is not specified then all entries are returned. If descend
is not specified then the algorithm traverses into all subdirectories. Symbolic links to directories are never followed, but are returned if the select
predicate allows them.
Definition at line 135 of file Rose/FileSystem.h.
Referenced by copyFilesRecursively(), and findNamesRecursively().
std::vector< Path > Rose::FileSystem::findNamesRecursively | ( | const Path & | root, |
Select | select | ||
) |
Recursive list of names satisfying predicate.
Returns a list of entries in a directory and all subdirectories recursively. The return value is a sorted list of paths, each of which contains root
as a prefix. If a select
predicate is supplied then only paths for which the predicate returns true become part of the return value. If a descend
predicate is supplied then this algorithm only recurses into subdirectories for which descend
returns true. The predicates are called with the path that would become part of the return value. The root
itself is never returned and never tested by the select
or descend
predicates.
If select
is not specified then all entries are returned. If descend
is not specified then the algorithm traverses into all subdirectories. Symbolic links to directories are never followed, but are returned if the select
predicate allows them.
Definition at line 151 of file Rose/FileSystem.h.
References findNamesRecursively(), and isDirectory().
Recursive list of names satisfying predicate.
Returns a list of entries in a directory and all subdirectories recursively. The return value is a sorted list of paths, each of which contains root
as a prefix. If a select
predicate is supplied then only paths for which the predicate returns true become part of the return value. If a descend
predicate is supplied then this algorithm only recurses into subdirectories for which descend
returns true. The predicates are called with the path that would become part of the return value. The root
itself is never returned and never tested by the select
or descend
predicates.
If select
is not specified then all entries are returned. If descend
is not specified then the algorithm traverses into all subdirectories. Symbolic links to directories are never followed, but are returned if the select
predicate allows them.
ROSE_UTIL_API void Rose::FileSystem::copyFile | ( | const Path & | sourceFileName, |
const Path & | destinationFileName | ||
) |
Copy a file.
Copies the contents of the source file to the destination file, overwriting the destination file if it existed.
ROSE_UTIL_API void Rose::FileSystem::copyFiles | ( | const std::vector< Path > & | files, |
const Path & | root, | ||
const Path & | destinationDirectory | ||
) |
Copy files from one directory to another.
Each of the specified files are copied from their location under root
to a similar location under destinationDirectory
. Subdirectories of the destination directory are created as necessary.
Any file whose name is outside the root
directory will similarly be created outside the destinationDirectory
. For instance, copyFiles(["bar/baz"], "foo", "frob") will copy "bar/baz" to "frob/../bar/baz" since "bar" is apparently a sibling of "foo", and therefore must be a sibling of "frob".
Throws a boost::filesystem::filesystem_error
on failure.
Referenced by copyFilesRecursively().
void Rose::FileSystem::copyFilesRecursively | ( | const Path & | root, |
const Path & | destination, | ||
Select | select, | ||
Descend | descend | ||
) |
Recursively copy files.
Get a list of files by recursively matching files under root
and then copy them to similar locations relative to destination
. The root
and destination
must not overlap. The select
and descend
arguments are the same as for the findNamesRecursively method.
Definition at line 181 of file Rose/FileSystem.h.
References copyFiles(), findNamesRecursively(), and isFile().
ROSE_UTIL_API std::string Rose::FileSystem::toString | ( | const Path & | ) |
Convert a path to a string.
Try not to use this. Paths contain more information than std::string and the conversion may loose that info.
Container Rose::FileSystem::readFile | ( | const boost::filesystem::path & | fileName, |
std::ios_base::openmode | openMode = std::ios_base::in | std::ios_base::binary |
||
) |
Load an entire file into an STL container.
Throws an exception if the file cannot be opened or the entire contents of the file cannot be read.
Definition at line 199 of file Rose/FileSystem.h.
void Rose::FileSystem::writeFile | ( | const boost::filesystem::path & | fileName, |
const Container & | data, | ||
std::ios_base::openmode | openMode = std::ios_base::out | std::ios_base::binary |
||
) |
Write a container to a file.
Writes the contents of the container to a file. Throws an exception if the file cannot be opened or not all the data can be written.
Definition at line 217 of file Rose/FileSystem.h.