ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cloudViewer::utility::filesystem Namespace Reference

Classes

class  CFile
 

Functions

template<typename... T>
std::string JoinPaths (T const &...paths)
 
std::string JoinPath (const std::vector< std::string > &path_components)
 
std::string JoinPath (const std::string &path_component1, const std::string &path_component2)
 
std::string GetEnvVar (const std::string &env_var)
 
std::string GetHomeDirectory ()
 Get the HOME directory for the user. More...
 
std::string EnsureTrailingSlash (const std::string &str)
 
bool HasFileExtension (const std::string &file_name, const std::string &ext)
 
void SplitFileExtension (const std::string &path, std::string *root, std::string *ext)
 
bool CopyFile (const std::string &from, const std::string &to)
 Copy a file. More...
 
bool CopyDir (const std::string &from, const std::string &to)
 Copy a directory. More...
 
bool CopyA (const std::string &src_path, const std::string &dst_path)
 
bool Copy (const std::string &from, const std::string &to, bool include_parent_dir=false, const std::string &extname="")
 Copy a file or directory. More...
 
std::string GetFileExtensionInLowerCase (const std::string &filename)
 
std::string GetFileNameWithoutExtension (const std::string &filename)
 
std::string GetFileNameWithoutDirectory (const std::string &filename)
 
std::string GetFileParentDirectory (const std::string &filename)
 
std::string GetRegularizedDirectoryName (const std::string &directory)
 
std::string GetFileBaseName (const std::string &filename)
 
std::string GetWorkingDirectory ()
 
std::vector< std::string > GetPathComponents (const std::string &path)
 
std::string GetTempDirectoryPath ()
 
bool ChangeWorkingDirectory (const std::string &directory)
 
bool IsFile (const std::string &filename)
 
bool IsDirectory (const std::string &directory)
 
bool DirectoryExists (const std::string &directory)
 
bool DirectoryIsEmpty (const std::string &directory)
 
bool EnsureDirectory (const std::string &directory_path)
 Check if a specified directory specified by directory_path exists. If not, recursively create the directory (and its parents). More...
 
bool MakeDirectory (const std::string &directory)
 
bool MakeDirectoryHierarchy (const std::string &directory)
 
bool DeleteDirectory (const std::string &directory)
 
bool FileExists (const std::string &filename)
 
bool RemoveFile (const std::string &filename)
 
bool ListDirectory (const std::string &directory, std::vector< std::string > &subdirs, std::vector< std::string > &filenames)
 
bool ListFilesInDirectory (const std::string &directory, std::vector< std::string > &filenames)
 
bool ListFilesInDirectoryWithExtension (const std::string &directory, const std::string &extname, std::vector< std::string > &filenames)
 
std::vector< std::string > FindFilesRecursively (const std::string &directory, std::function< bool(const std::string &)> is_match)
 
FILE * FOpen (const std::string &filename, const std::string &mode)
 
std::string GetIOErrorString (const int errnoVal)
 
bool FReadToBuffer (const std::string &path, std::vector< char > &bytes, std::string *errorStr)
 
std::string AddIfExist (const std::string &path, const std::vector< std::string > &folder_names)
 

Function Documentation

◆ AddIfExist()

std::string cloudViewer::utility::filesystem::AddIfExist ( const std::string &  path,
const std::vector< std::string > &  folder_names 
)

Definition at line 726 of file FileSystem.cpp.

References DirectoryExists(), JoinPath(), and cloudViewer::t::geometry::path.

◆ ChangeWorkingDirectory()

bool cloudViewer::utility::filesystem::ChangeWorkingDirectory ( const std::string &  directory)

◆ Copy()

bool cloudViewer::utility::filesystem::Copy ( const std::string &  from,
const std::string &  to,
bool  include_parent_dir = false,
const std::string &  extname = "" 
)

Copy a file or directory.

Parameters
fromThe path to copy from.
toThe path to copy to.
include_parent_dirWhether copy parent directory or not.
Returns
If the action is successful.

Definition at line 249 of file FileSystem.cpp.

References CopyDir(), CopyFile(), GetFileNameWithoutDirectory(), IsDirectory(), JoinPaths(), ListFilesInDirectoryWithExtension(), and LogWarning.

Referenced by cloudViewer::data::DownloadDataset::DownloadDataset(), and ecvCustomQListWidget::keyPressEvent().

◆ CopyA()

bool cloudViewer::utility::filesystem::CopyA ( const std::string &  src_path,
const std::string &  dst_path 
)

Definition at line 236 of file FileSystem.cpp.

References copy, and LogWarning.

Referenced by CopyFile().

◆ CopyDir()

bool cloudViewer::utility::filesystem::CopyDir ( const std::string &  from,
const std::string &  to 
)

Copy a directory.

Parameters
fromThe path to copy from [Note: not including 'from' folder].
toThe path to copy to.
Returns
If the action is successful.

Definition at line 202 of file FileSystem.cpp.

References CopyFile(), EnsureDirectory(), and LogError.

Referenced by Copy().

◆ CopyFile()

bool cloudViewer::utility::filesystem::CopyFile ( const std::string &  from,
const std::string &  to 
)

Copy a file.

Parameters
fromThe file path to copy from.
toThe file path to copy to.
Returns
If the action is successful.

Definition at line 163 of file FileSystem.cpp.

References CopyA(), IsDirectory(), LogError, and LogWarning.

Referenced by Copy(), and CopyDir().

◆ DeleteDirectory()

bool cloudViewer::utility::filesystem::DeleteDirectory ( const std::string &  directory)

Definition at line 514 of file FileSystem.cpp.

References error(), and LogWarning.

◆ DirectoryExists()

◆ DirectoryIsEmpty()

bool cloudViewer::utility::filesystem::DirectoryIsEmpty ( const std::string &  directory)

Definition at line 477 of file FileSystem.cpp.

References DirectoryExists(), and LogError.

◆ EnsureDirectory()

bool cloudViewer::utility::filesystem::EnsureDirectory ( const std::string &  directory_path)

Check if a specified directory specified by directory_path exists. If not, recursively create the directory (and its parents).

Parameters
directory_pathDirectory path.
Returns
If the directory does exist or its creation is successful.

Definition at line 484 of file FileSystem.cpp.

References DirectoryExists(), and MakeDirectoryHierarchy().

Referenced by CopyDir().

◆ EnsureTrailingSlash()

std::string cloudViewer::utility::filesystem::EnsureTrailingSlash ( const std::string &  str)

Definition at line 106 of file FileSystem.cpp.

◆ FileExists()

◆ FindFilesRecursively()

std::vector< std::string > cloudViewer::utility::filesystem::FindFilesRecursively ( const std::string &  directory,
std::function< bool(const std::string &)>  is_match 
)

Definition at line 586 of file FileSystem.cpp.

References ListDirectory().

Referenced by cloudViewer::visualization::gui::FindFontPath().

◆ FOpen()

◆ FReadToBuffer()

◆ GetEnvVar()

std::string cloudViewer::utility::filesystem::GetEnvVar ( const std::string &  env_var)

Definition at line 66 of file FileSystem.cpp.

Referenced by GetHomeDirectory().

◆ GetFileBaseName()

std::string cloudViewer::utility::filesystem::GetFileBaseName ( const std::string &  filename)

◆ GetFileExtensionInLowerCase()

◆ GetFileNameWithoutDirectory()

◆ GetFileNameWithoutExtension()

std::string cloudViewer::utility::filesystem::GetFileNameWithoutExtension ( const std::string &  filename)

◆ GetFileParentDirectory()

◆ GetHomeDirectory()

std::string cloudViewer::utility::filesystem::GetHomeDirectory ( )

Get the HOME directory for the user.

The home directory is determined in the following order:

  • On Unix:
    • $HOME
    • /
  • On Windows:
    • USERPROFILE%
    • HOMEDRIVE%
    • HOMEPATH%
    • HOME%
    • C:/

This is the same logics as used in Qt.

  • src/corelib/io/qfilesystemengine_win.cpp
  • src/corelib/io/qfilesystemengine_unix.cpp

Definition at line 74 of file FileSystem.cpp.

References DirectoryExists(), and GetEnvVar().

Referenced by cloudViewer::data::LocateDataRoot().

◆ GetIOErrorString()

std::string cloudViewer::utility::filesystem::GetIOErrorString ( const int  errnoVal)

◆ GetPathComponents()

std::vector< std::string > cloudViewer::utility::filesystem::GetPathComponents ( const std::string &  path)

◆ GetRegularizedDirectoryName()

std::string cloudViewer::utility::filesystem::GetRegularizedDirectoryName ( const std::string &  directory)

Definition at line 323 of file FileSystem.cpp.

Referenced by ListDirectory(), main(), and MakeDirectoryHierarchy().

◆ GetTempDirectoryPath()

std::string cloudViewer::utility::filesystem::GetTempDirectoryPath ( )

Definition at line 423 of file FileSystem.cpp.

◆ GetWorkingDirectory()

std::string cloudViewer::utility::filesystem::GetWorkingDirectory ( )

◆ HasFileExtension()

bool cloudViewer::utility::filesystem::HasFileExtension ( const std::string &  file_name,
const std::string &  ext 
)

Definition at line 117 of file FileSystem.cpp.

References LogWarning, and cloudViewer::utility::ToLower().

◆ IsDirectory()

bool cloudViewer::utility::filesystem::IsDirectory ( const std::string &  directory)

Definition at line 454 of file FileSystem.cpp.

Referenced by Copy(), and CopyFile().

◆ IsFile()

bool cloudViewer::utility::filesystem::IsFile ( const std::string &  filename)

Definition at line 435 of file FileSystem.cpp.

References filename.

◆ JoinPath() [1/2]

std::string cloudViewer::utility::filesystem::JoinPath ( const std::string &  path_component1,
const std::string &  path_component2 
)

Definition at line 52 of file FileSystem.cpp.

References cloudViewer::t::geometry::path.

◆ JoinPath() [2/2]

std::string cloudViewer::utility::filesystem::JoinPath ( const std::vector< std::string > &  path_components)

Definition at line 58 of file FileSystem.cpp.

References cloudViewer::t::geometry::path.

Referenced by AddIfExist().

◆ JoinPaths()

◆ ListDirectory()

bool cloudViewer::utility::filesystem::ListDirectory ( const std::string &  directory,
std::vector< std::string > &  subdirs,
std::vector< std::string > &  filenames 
)

◆ ListFilesInDirectory()

bool cloudViewer::utility::filesystem::ListFilesInDirectory ( const std::string &  directory,
std::vector< std::string > &  filenames 
)

◆ ListFilesInDirectoryWithExtension()

bool cloudViewer::utility::filesystem::ListFilesInDirectoryWithExtension ( const std::string &  directory,
const std::string &  extname,
std::vector< std::string > &  filenames 
)

Definition at line 567 of file FileSystem.cpp.

References GetFileExtensionInLowerCase(), and ListFilesInDirectory().

Referenced by Copy().

◆ MakeDirectory()

◆ MakeDirectoryHierarchy()

◆ RemoveFile()

bool cloudViewer::utility::filesystem::RemoveFile ( const std::string &  filename)

Definition at line 528 of file FileSystem.cpp.

References filename.

◆ SplitFileExtension()

void cloudViewer::utility::filesystem::SplitFileExtension ( const std::string &  path,
std::string *  root,
std::string *  ext 
)