Geogram
Version 1.9.1-rc
A programming library of geometric algorithms
|
Abstraction layer for file-system management. More...
Classes | |
class | Node |
A Node in a FileSystem. More... | |
class | MemoryNode |
Implementation of a file system stored in memory. More... | |
Typedefs | |
typedef SmartPointer< Node > | Node_var |
Functions | |
void | initialize () |
Initializes the FileSystem library. More... | |
void | terminate () |
Terminates the FileSystem library. More... | |
bool | is_file (const std::string &path) |
Checks if a path is a regular file. More... | |
bool | is_directory (const std::string &path) |
Checks if a path is a directory. More... | |
bool | can_read_directory (const std::string &path) |
Tests whether one can read files from a directory. More... | |
bool | can_write_directory (const std::string &path, bool create_missing_directories=false) |
Tests whether a directory can be written to. More... | |
bool | create_directory (const std::string &path) |
Creates a directory. More... | |
bool | delete_directory (const std::string &path) |
Deletes a directory. More... | |
bool | delete_file (const std::string &path) |
Deletes a file. More... | |
bool | get_directory_entries (const std::string &path, std::vector< std::string > &result) |
Lists directory contents. More... | |
std::string | get_current_working_directory () |
Gets the current working directory. More... | |
bool | set_current_working_directory (const std::string &path) |
bool | rename_file (const std::string &old_name, const std::string &new_name) |
Renames or moves a file. More... | |
Numeric::uint64 | get_time_stamp (const std::string &path) |
Gets a file last modification time. More... | |
std::string | extension (const std::string &path) |
Gets a path extension. More... | |
std::string | base_name (const std::string &path, bool remove_extension=true) |
Gets a path base name. More... | |
std::string | dir_name (const std::string &path) |
Gets a path directory. More... | |
void | get_directory_entries (const std::string &path, std::vector< std::string > &result, bool recursive) |
Lists directory contents. More... | |
void | get_files (const std::string &path, std::vector< std::string > &result, bool recursive=false) |
Lists files in a directory. More... | |
void | get_subdirectories (const std::string &path, std::vector< std::string > &result, bool recursive=false) |
Lists sub-directories in a directory. More... | |
void | flip_slashes (std::string &path) |
Converts a path to Unix format. More... | |
bool | copy_file (const std::string &from, const std::string &to) |
Copies a file. More... | |
bool | set_executable_flag (const std::string &filename) |
Marks a filename as executable. More... | |
bool | touch (const std::string &filename) |
Modifies the last modification time of a file. More... | |
std::string | normalized_path (const std::string &path) |
Normalizes a path. More... | |
std::string | absolute_path (const std::string &path) |
std::string | home_directory () |
Gets the current user's home directory. More... | |
std::string | documents_directory () |
Gets the current user's home directory. More... | |
void | get_root (Node *&root) |
Gets the root of the file system. More... | |
Abstraction layer for file-system management.
std::string GEO::FileSystem::absolute_path | ( | const std::string & | path | ) |
std::string GEO::FileSystem::base_name | ( | const std::string & | path, |
bool | remove_extension = true |
||
) |
Gets a path base name.
Extracts the base name from the path path
, that is any character that appear after the last directory separator. If parameter remove_extension
is true
(the default), the extension is removed from the base name, otherwise is it kept. If the path does not contain any directory separator, the whole path is returned.
Examples
[in] | path | the path to a file or directory |
[in] | remove_extension | whether to remove the extension from the base name or not. |
bool GEO::FileSystem::can_read_directory | ( | const std::string & | path | ) |
Tests whether one can read files from a directory.
[in] | path | the directory to be tested, either absolute or relative to current working directory. |
true | if one can read files in path |
false | otherwise |
bool GEO::FileSystem::can_write_directory | ( | const std::string & | path, |
bool | create_missing_directories = false |
||
) |
Tests whether a directory can be written to.
[in] | path | the directory to be tested, either absolute or relative to current working directory. |
[in] | create_missing_directories | if set, then the function tentatively creates the subdirectories that do not already exist (as "mkdir -p" does). |
bool GEO::FileSystem::copy_file | ( | const std::string & | from, |
const std::string & | to | ||
) |
Copies a file.
[in] | from | name of the file to be copied |
[out] | to | name of the copy |
true | if the copy was successful |
false | otherwise |
bool GEO::FileSystem::create_directory | ( | const std::string & | path | ) |
Creates a directory.
This recursively creates a new directory given by its absolute path path
, creating any missing intermediate directories on the fly.
[in] | path | absolute path to the directory to be created. |
true | if the directory was successfully created. |
false | otherwise. |
bool GEO::FileSystem::delete_directory | ( | const std::string & | path | ) |
Deletes a directory.
This deletes the directory specified by path path
. The path must specify an empty directory.
[in] | path | the path of the directory to be removed. |
true | if the directory was successfully deleted. |
false | otherwise. |
bool GEO::FileSystem::delete_file | ( | const std::string & | path | ) |
Deletes a file.
[in] | path | the path of the file to be deleted. |
true | if the file path was successfully deleted |
false | otherwise |
std::string GEO::FileSystem::dir_name | ( | const std::string & | path | ) |
Gets a path directory.
Extracts the directory from the path path
, that is any character that appear before the last directory separator. If the path does not contain any directory separator, string "." is returned.
Examples
[in] | path | the path to a file or directory |
std::string GEO::FileSystem::documents_directory | ( | ) |
Gets the current user's home directory.
Under unix, it returns the content of the HOME environment variable. Under Windows, it returns the "My Documents" directory.
std::string GEO::FileSystem::extension | ( | const std::string & | path | ) |
Gets a path extension.
Extracts the extension from the path path
, that is any character that appear after the last dot (.) and after any directory separator character. If path
has no extension, the empty string is returned.
Examples
[in] | path | the path to a file or directory |
void GEO::FileSystem::flip_slashes | ( | std::string & | path | ) |
Converts a path to Unix format.
It changes all Windows "\" directory separators into Unix "/" directory separators.
[in,out] | path | the path to be converted |
std::string GEO::FileSystem::get_current_working_directory | ( | ) |
Gets the current working directory.
bool GEO::FileSystem::get_directory_entries | ( | const std::string & | path, |
std::vector< std::string > & | result | ||
) |
Lists directory contents.
Lists all the files and sub-directories in the directory specified by path
, and stores the list in result
. Special entries "." and ".." are not stored in result
.
[in] | path | the path to the directory to list. |
[in] | result | output vector of files and sub-directories. |
true | if path specifies a readable directory. |
false | otherwise. |
void GEO::FileSystem::get_directory_entries | ( | const std::string & | path, |
std::vector< std::string > & | result, | ||
bool | recursive | ||
) |
Lists directory contents.
Lists all the files and sub-directories in the directory specified by path
, and stores the list in result
. Special entries "." and ".." are not stored in result
.
[in] | path | the path to the directory to list. |
[in] | result | output vector of files and sub-directories. |
true | if path specifies a readable directory. |
false | otherwise. |
void GEO::FileSystem::get_files | ( | const std::string & | path, |
std::vector< std::string > & | result, | ||
bool | recursive = false |
||
) |
Lists files in a directory.
Lists all the files in the directory specified by path
, and stores the list in result
. Special entries "." and ".." are not stored in result
. If parameter recursive is set to true
, result
will include the entries of all sub-directories in path
recursively.
[in] | path | the path to an existing directory |
[in] | result | output vector of files in path |
[in] | recursive | recursively traverses all sub-directories in path |
void GEO::FileSystem::get_root | ( | Node *& | root | ) |
Gets the root of the file system.
[out] | root | a pointer to the root of the FileSystem. |
void GEO::FileSystem::get_subdirectories | ( | const std::string & | path, |
std::vector< std::string > & | result, | ||
bool | recursive = false |
||
) |
Lists sub-directories in a directory.
Lists all the sub-directories in the directory specified by path
, and stores the list in result
. Special entries "." and ".." are not stored in result
. If parameter recursive is set to true
, result
will include the entries of all sub-directories in path
recursively.
[in] | path | the path to an existing directory |
[in] | result | output vector of sub-directories in path |
[in] | recursive | recursively traverses all sub-directories in path |
Numeric::uint64 GEO::FileSystem::get_time_stamp | ( | const std::string & | path | ) |
Gets a file last modification time.
[in] | path | the path to an existing file or directory. |
std::string GEO::FileSystem::home_directory | ( | ) |
Gets the current user's home directory.
void GEO::FileSystem::initialize | ( | ) |
Initializes the FileSystem library.
This function is automatically called during Geogram startup. It should not be called by client code.
bool GEO::FileSystem::is_directory | ( | const std::string & | path | ) |
Checks if a path is a directory.
[in] | path | system path to verify. |
true | if path is a directory. |
false | otherwise. |
bool GEO::FileSystem::is_file | ( | const std::string & | path | ) |
Checks if a path is a regular file.
[in] | path | system path to verify. |
true | if path is a regular file. |
false | otherwise. |
std::string GEO::FileSystem::normalized_path | ( | const std::string & | path | ) |
Normalizes a path.
A path is normalized if it is absolute and it does not contain any "../" component.
[in] | path | the path to be normalized. The path can have components that do not exist. |
bool GEO::FileSystem::rename_file | ( | const std::string & | old_name, |
const std::string & | new_name | ||
) |
Renames or moves a file.
This renames the existing file or directory specified by path old_name
to the new path new_name
. The new name must not be the name of an existing file or directory. If old_name
and new_name
are not in the same directory, old_name
is moved to the new_name
.
[in] | old_name | path of the file or directory to be renamed. |
[in] | new_name | new path of the file or directory. |
true | if the file was renamed successfully. |
false | otherwise. |
bool GEO::FileSystem::set_executable_flag | ( | const std::string & | filename | ) |
Marks a filename as executable.
On unix, it chmods the file, on Windows, does nothing.
[in] | filename | name of the file to be made executable |
true | on success. |
false | otherwise. |
void GEO::FileSystem::terminate | ( | ) |
Terminates the FileSystem library.
This function is automatically called during Geogram shutdown. It should not be called by client code.
bool GEO::FileSystem::touch | ( | const std::string & | filename | ) |
Modifies the last modification time of a file.
[in] | filename | name of the file. |
true | on success. |
false | otherwise. |