Geogram  Version 1.9.1
A programming library of geometric algorithms
GEO::FileSystem::Node Class Reference

A Node in a FileSystem. More...

#include <geogram/basic/file_system.h>

Inheritance diagram for GEO::FileSystem::Node:
GEO::Counted GEO::FileSystem::MemoryNode

Public Member Functions

 Node ()
 Node constructor.
 
 ~Node () override
 Node destructor.
 
virtual bool is_file (const std::string &path)
 Checks if a path is a regular file. More...
 
virtual bool is_directory (const std::string &path)
 Checks if a path is a directory. More...
 
virtual bool create_directory (const std::string &path)
 Creates a directory. More...
 
virtual bool delete_directory (const std::string &path)
 Deletes a directory. More...
 
virtual bool delete_file (const std::string &path)
 Deletes a file. More...
 
virtual bool get_directory_entries (const std::string &path, std::vector< std::string > &result)
 Lists directory contents. More...
 
virtual std::string get_current_working_directory ()
 Gets the current working directory. More...
 
virtual bool set_current_working_directory (const std::string &path)
 Sets the working directory. More...
 
virtual bool rename_file (const std::string &old_name, const std::string &new_name)
 Renames or moves a file. More...
 
virtual Numeric::uint64 get_time_stamp (const std::string &path)
 Gets a file last modification time. More...
 
virtual bool set_executable_flag (const std::string &filename)
 Marks a filename as executable. More...
 
virtual bool touch (const std::string &filename)
 Modifies the last modification time of a file. More...
 
virtual std::string normalized_path (const std::string &path)
 Normalizes a path. More...
 
virtual std::string home_directory ()
 Gets the current user's home directory. More...
 
virtual std::string documents_directory ()
 Gets the current user's home directory. More...
 
virtual std::string load_file_as_string (const std::string &path)
 Load file contents in a string. More...
 
virtual std::string extension (const std::string &path)
 Gets a path extension. More...
 
virtual std::string base_name (const std::string &path, bool remove_extension=true)
 Gets a path base name. More...
 
virtual std::string dir_name (const std::string &path)
 Gets a path directory. More...
 
virtual void get_directory_entries (const std::string &path, std::vector< std::string > &result, bool recursive)
 Lists directory contents. More...
 
virtual void get_files (const std::string &path, std::vector< std::string > &result, bool recursive=false)
 Lists files in a directory. More...
 
virtual void get_subdirectories (const std::string &path, std::vector< std::string > &result, bool recursive=false)
 Lists sub-directories in a directory. More...
 
virtual void flip_slashes (std::string &path)
 Converts a path to Unix format. More...
 
virtual bool copy_file (const std::string &from, const std::string &to)
 Copies a file. More...
 
- Public Member Functions inherited from GEO::Counted
void ref () const
 Increments the reference count. More...
 
void unref () const
 Decrements the reference count. More...
 
bool is_shared () const
 Check if the object is shared. More...
 
int nb_refs () const
 Gets the number of references that point to this object. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from GEO::Counted
static void ref (const Counted *counted)
 Increments the reference count. More...
 
static void unref (const Counted *counted)
 Decrements the reference count. More...
 
- Protected Member Functions inherited from GEO::Counted
 Counted ()
 Creates a reference counted object. More...
 
virtual ~Counted ()
 Destroys a reference counted object. More...
 

Detailed Description

A Node in a FileSystem.

This class abstracts a FileSystem and operations on it.

Definition at line 69 of file file_system.h.

Member Function Documentation

◆ base_name()

virtual std::string GEO::FileSystem::Node::base_name ( const std::string &  path,
bool  remove_extension = true 
)
virtual

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

  • base_name("/dir/file.cpp") -> "file"
  • base_name("/dir/file.cpp", false) -> "file.cpp"
  • base_name("file") -> "file"
Parameters
[in]paththe path to a file or directory
[in]remove_extensionwhether to remove the extension from the base name or not.

◆ copy_file()

virtual bool GEO::FileSystem::Node::copy_file ( const std::string &  from,
const std::string &  to 
)
virtual

Copies a file.

Parameters
[in]fromname of the file to be copied
[out]toname of the copy
Return values
trueif the copy was successful
falseotherwise

Reimplemented in GEO::FileSystem::MemoryNode.

◆ create_directory()

virtual bool GEO::FileSystem::Node::create_directory ( const std::string &  path)
virtual

Creates a directory.

This recursively creates a new directory given by its absolute path path, creating any missing intermediate directories on the fly.

Parameters
[in]pathabsolute path to the directory to be created.
Return values
trueif the directory was successfully created.
falseotherwise.

Reimplemented in GEO::FileSystem::MemoryNode.

◆ delete_directory()

virtual bool GEO::FileSystem::Node::delete_directory ( const std::string &  path)
virtual

Deletes a directory.

This deletes the directory specified by path path. The path must specify an empty directory.

Parameters
[in]paththe path of the directory to be removed.
Return values
trueif the directory was successfully deleted.
falseotherwise.

Reimplemented in GEO::FileSystem::MemoryNode.

◆ delete_file()

virtual bool GEO::FileSystem::Node::delete_file ( const std::string &  path)
virtual

Deletes a file.

Parameters
[in]paththe path of the file to be deleted.
Return values
trueif the file path was successfully deleted
falseotherwise

Reimplemented in GEO::FileSystem::MemoryNode.

◆ dir_name()

virtual std::string GEO::FileSystem::Node::dir_name ( const std::string &  path)
virtual

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

  • dir_name("/dir/file.cpp") -> "dir"
  • dir_name("file") -> "."
  • dir_name("/") -> "/"
Parameters
[in]paththe path to a file or directory
Returns
the path directory or "." if none

◆ documents_directory()

virtual std::string GEO::FileSystem::Node::documents_directory ( )
virtual

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.

Returns
The path to the current user's home directory as a string.

◆ extension()

virtual std::string GEO::FileSystem::Node::extension ( const std::string &  path)
virtual

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

  • extension("/dir/file.cpp") -> "cpp"
  • extension("file") -> ""
  • extension("/dir.ext/file") -> ""
Parameters
[in]paththe path to a file or directory
Returns
the path's extension (without the dot), or the empty string if none.

◆ flip_slashes()

virtual void GEO::FileSystem::Node::flip_slashes ( std::string &  path)
virtual

Converts a path to Unix format.

It changes all Windows "\" directory separators into Unix "/" directory separators.

Parameters
[in,out]paththe path to be converted

◆ get_current_working_directory()

virtual std::string GEO::FileSystem::Node::get_current_working_directory ( )
virtual

Gets the current working directory.

Returns
The absolute path to the current directory.

◆ get_directory_entries() [1/2]

virtual bool GEO::FileSystem::Node::get_directory_entries ( const std::string &  path,
std::vector< std::string > &  result 
)
virtual

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.

Parameters
[in]paththe path to the directory to list.
[in]resultoutput vector of files and sub-directories.
Return values
trueif path specifies a readable directory.
falseotherwise.

Reimplemented in GEO::FileSystem::MemoryNode.

◆ get_directory_entries() [2/2]

virtual void GEO::FileSystem::Node::get_directory_entries ( const std::string &  path,
std::vector< std::string > &  result,
bool  recursive 
)
virtual

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. If parameter recursive is set to true, result will include the entries of all sub-directories in path recursively.

Parameters
[in]paththe path to an existing directory
[in]resultoutput vector of entries in path
[in]recursiverecursively traverses all sub-directories in path

◆ get_files()

virtual void GEO::FileSystem::Node::get_files ( const std::string &  path,
std::vector< std::string > &  result,
bool  recursive = false 
)
virtual

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.

Parameters
[in]paththe path to an existing directory
[in]resultoutput vector of files in path
[in]recursiverecursively traverses all sub-directories in path
See also
get_directory_entries()

◆ get_subdirectories()

virtual void GEO::FileSystem::Node::get_subdirectories ( const std::string &  path,
std::vector< std::string > &  result,
bool  recursive = false 
)
virtual

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.

Parameters
[in]paththe path to an existing directory
[in]resultoutput vector of sub-directories in path
[in]recursiverecursively traverses all sub-directories in path
See also
get_directory_entries()

◆ get_time_stamp()

virtual Numeric::uint64 GEO::FileSystem::Node::get_time_stamp ( const std::string &  path)
virtual

Gets a file last modification time.

Parameters
[in]paththe path to an existing file or directory.
Returns
the last modification time in seconds

◆ home_directory()

virtual std::string GEO::FileSystem::Node::home_directory ( )
virtual

Gets the current user's home directory.

Returns
The path to the current user's home directory as a string.

◆ is_directory()

virtual bool GEO::FileSystem::Node::is_directory ( const std::string &  path)
virtual

Checks if a path is a directory.

Parameters
[in]pathsystem path to verify.
Return values
trueif path is a directory.
falseotherwise.

Reimplemented in GEO::FileSystem::MemoryNode.

◆ is_file()

virtual bool GEO::FileSystem::Node::is_file ( const std::string &  path)
virtual

Checks if a path is a regular file.

Parameters
[in]pathsystem path to verify.
Return values
trueif path is a regular file.
falseotherwise.

Reimplemented in GEO::FileSystem::MemoryNode.

◆ load_file_as_string()

virtual std::string GEO::FileSystem::Node::load_file_as_string ( const std::string &  path)
virtual

Load file contents in a string.

Parameters
[in]paththe path to the file
Returns
a string with the contents of the file.

Reimplemented in GEO::FileSystem::MemoryNode.

◆ normalized_path()

virtual std::string GEO::FileSystem::Node::normalized_path ( const std::string &  path)
virtual

Normalizes a path.

A path is normalized if it is absolute and it does not contain any "../" component.

Parameters
[in]paththe path to be normalized. The path can have components that do not exist.
Returns
the normalized path

◆ rename_file()

virtual bool GEO::FileSystem::Node::rename_file ( const std::string &  old_name,
const std::string &  new_name 
)
virtual

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.

Parameters
[in]old_namepath of the file or directory to be renamed.
[in]new_namenew path of the file or directory.
Return values
trueif the file was renamed successfully.
falseotherwise.

Reimplemented in GEO::FileSystem::MemoryNode.

◆ set_current_working_directory()

virtual bool GEO::FileSystem::Node::set_current_working_directory ( const std::string &  path)
virtual

Sets the working directory.

Parameters
[in]pathpath to the new working directory.
Return values
trueif the current directory could be changed to path.
falseotherwise.

◆ set_executable_flag()

virtual bool GEO::FileSystem::Node::set_executable_flag ( const std::string &  filename)
virtual

Marks a filename as executable.

On unix, it chmods the file, on Windows, does nothing.

Parameters
[in]filenamename of the file to be made executable
Return values
trueon success.
falseotherwise.

◆ touch()

virtual bool GEO::FileSystem::Node::touch ( const std::string &  filename)
virtual

Modifies the last modification time of a file.

Parameters
[in]filenamename of the file.
Return values
trueon success.
falseotherwise.

The documentation for this class was generated from the following file: