Base::FileInfo Class Reference

File name unification This class handles everything related to file names the file names are internal generally UTF-8 encoded on all platforms. More...

#include <FileInfo.h>

Public Types

enum  Permissions { WriteOnly = 0x01 , ReadOnly = 0x02 , ReadWrite = 0x03 }
 

Public Member Functions

 FileInfo (const char *_FileName="")
 Construction. More...
 
 FileInfo (const std::string &_FileName)
 
void setFile (const char *name)
 Set a new file name. More...
 
void setFile (const std::string &name)
 Set a new file name. More...
 
extraction of information
std::string filePath () const
 Returns the file name, including the path (which may be absolute or relative). More...
 
std::string dirPath () const
 Returns the dir path name (which may be absolute or relative). More...
 
std::string fileName () const
 Returns the name of the file, excluding the path, including the extension. More...
 
std::string fileNamePure () const
 Returns the name of the file, excluding the path and the extension. More...
 
std::wstring toStdWString () const
 Convert the path name into a UTF-16 encoded wide string format. More...
 
std::string extension () const
 Returns the extension of the file. More...
 
std::string completeExtension () const
 Returns the complete extension of the file. More...
 
bool hasExtension (const char *Ext) const
 Checks for a special extension, NOT case sensitive. More...
 
methods to test the status of the file or dir
bool exists () const
 Does the file exist? More...
 
bool isReadable () const
 Checks if the file exist and is readable. More...
 
bool isWritable () const
 Checks if the file exist and is writable. More...
 
bool setPermissions (Permissions)
 Tries to set the file permission. More...
 
bool isFile () const
 Checks if it is a file (not a directory) More...
 
bool isDir () const
 Checks if it is a directory (not a file) More...
 
unsigned int size () const
 The size of the file. More...
 
TimeInfo lastModified () const
 Returns the time when the file was last modified. More...
 
TimeInfo lastRead () const
 Returns the time when the file was last read (accessed). More...
 
Directory management
bool createDirectory () const
 Creates a directory. Returns true if successful; otherwise returns false. More...
 
bool createDirectories () const
 Creates a directory and all its parent directories. Returns true if successful; otherwise returns false. More...
 
std::vector< Base::FileInfogetDirectoryContent () const
 Get a list of the directory content. More...
 
bool deleteDirectory () const
 Delete an empty directory. More...
 
bool deleteDirectoryRecursive () const
 Delete a directory and all its content. More...
 
bool deleteFile () const
 Delete the file. More...
 
bool renameFile (const char *NewName)
 Rename the file. More...
 
bool copyTo (const char *NewName) const
 Rename the file. More...
 

Tools

std::string FileName
 
static std::string getTempFileName (const char *FileName=nullptr, const char *path=nullptr)
 Get a unique File Name in the given or (if 0) in the temp path. More...
 
static const std::string & getTempPath ()
 Get the path to the dir which is considered to temp files. More...
 
static std::string pathToString (const boost::filesystem::path &p)
 Convert from filesystem path to string. More...
 
static boost::filesystem::path stringToPath (const std::string &str)
 Convert from string to filesystem path. More...
 

Detailed Description

File name unification This class handles everything related to file names the file names are internal generally UTF-8 encoded on all platforms.

Member Enumeration Documentation

◆ Permissions

Enumerator
WriteOnly 
ReadOnly 
ReadWrite 

Constructor & Destructor Documentation

◆ FileInfo() [1/2]

FileInfo::FileInfo ( const char *  _FileName = "")

Construction.

References setFile().

Referenced by getDirectoryContent().

◆ FileInfo() [2/2]

FileInfo::FileInfo ( const std::string &  _FileName)

References setFile().

Member Function Documentation

◆ completeExtension()

std::string FileInfo::completeExtension ( ) const

Returns the complete extension of the file.

The complete extension consists of all characters in the file after (but not including) the first '.' character.

FileInfo fi( "/tmp/archive.tar.gz" );
ext = fi.completeExtension(); // ext = "tar.gz"

References FileName.

◆ copyTo()

bool FileInfo::copyTo ( const char *  NewName) const

Rename the file.

References FileName, and toStdWString().

Referenced by TechDraw::DrawUtil::copyFile(), and App::PropertyFileIncluded::Paste().

◆ createDirectories()

bool FileInfo::createDirectories ( ) const

Creates a directory and all its parent directories. Returns true if successful; otherwise returns false.

References FileName, and stringToPath().

Referenced by App::Document::onChanged().

◆ createDirectory()

bool FileInfo::createDirectory ( ) const

Creates a directory. Returns true if successful; otherwise returns false.

References FileName, and toStdWString().

Referenced by App::VRMLObject::makeDirectories(), Gui::AutoSaver::slotCreateDocument(), Base::FileWriter::writeFiles(), and Gui::RecoveryWriter::writeFiles().

◆ deleteDirectory()

bool FileInfo::deleteDirectory ( ) const

Delete an empty directory.

References FileName, isDir(), and toStdWString().

Referenced by deleteDirectoryRecursive().

◆ deleteDirectoryRecursive()

bool FileInfo::deleteDirectoryRecursive ( ) const

Delete a directory and all its content.

References deleteDirectory(), getDirectoryContent(), isDir(), and ReadWrite.

Referenced by App::Document::~Document().

◆ deleteFile()

◆ dirPath()

◆ exists()

◆ extension()

std::string FileInfo::extension ( ) const

◆ fileName()

◆ fileNamePure()

◆ filePath()

std::string FileInfo::filePath ( ) const

Returns the file name, including the path (which may be absolute or relative).

References FileName.

Referenced by Mesh::AmfExporter::AmfExporter(), App::Application::closeDocument(), App::PropertyFileIncluded::Copy(), Gui::MainWindow::createMimeDataFromSelection(), Drawing::FeaturePage::execute(), Raytracing::LuxProject::execute(), Raytracing::RayProject::execute(), TechDraw::DrawSVGTemplate::execute(), Gui::Application::exportTo(), WebGui::FcCookieJar::FcCookieJar(), Base::FileException::FileException(), App::Application::getDocumentByPath(), TechDraw::DrawSVGTemplate::getEditableTextsFromTemplate(), Drawing::FeaturePage::getEditableTextsFromTemplate(), CDxfWrite::getPlateFile(), App::PropertyFileIncluded::getUniqueFileName(), Gui::Application::importFrom(), App::Document::onChanged(), Drawing::FeaturePage::onDocumentRestored(), Raytracing::LuxProject::onDocumentRestored(), Raytracing::RayProject::onDocumentRestored(), Gui::Application::open(), App::Application::openDocumentPrivate(), Gui::SoSVGVectorOutput::openFile(), Gui::SoU3DVectorOutput::openFile(), App::PropertyFileIncluded::Paste(), Fem::FemPostPipeline::read(), Fem::FemMesh::read(), Part::TopoShape::read(), Fem::FemMesh::RestoreDocFile(), Fem::PropertyPostDataObject::RestoreDocFile(), Gui::Application::sAddCommand(), App::PropertyFileIncluded::Save(), Fem::FemMesh::SaveDocFile(), Fem::PropertyPostDataObject::SaveDocFile(), App::PropertyFileIncluded::setValue(), Fem::FemMesh::write(), Part::TopoShape::write(), and MeshGui::RemeshGmsh::writeProject().

◆ getDirectoryContent()

std::vector< Base::FileInfo > FileInfo::getDirectoryContent ( ) const

Get a list of the directory content.

References FileInfo(), FileName, and toStdWString().

Referenced by deleteDirectoryRecursive().

◆ getTempFileName()

std::string FileInfo::getTempFileName ( const char *  FileName = nullptr,
const char *  path = nullptr 
)
static

Get a unique File Name in the given or (if 0) in the temp path.

References FileName, getTempPath(), and draftgeoutils.general::vec().

Referenced by App::PropertyFileIncluded::getExchangeTempFile(), and App::Application::getTempFileName().

◆ getTempPath()

const std::string & FileInfo::getTempPath ( )
static

Get the path to the dir which is considered to temp files.

References isDir().

Referenced by getTempFileName().

◆ hasExtension()

◆ isDir()

bool FileInfo::isDir ( ) const

Checks if it is a directory (not a file)

References exists(), FileName, and toStdWString().

Referenced by deleteDirectory(), deleteDirectoryRecursive(), and getTempPath().

◆ isFile()

bool FileInfo::isFile ( ) const

Checks if it is a file (not a directory)

References exists(), FileName, and toStdWString().

Referenced by MeshCore::MeshInput::LoadAny(), and Gui::Application::sLoadFile().

◆ isReadable()

◆ isWritable()

bool FileInfo::isWritable ( ) const

Checks if the file exist and is writable.

References FileName, and toStdWString().

Referenced by Mesh::AmfExporter::AmfExporter(), App::PropertyFileIncluded::RestoreDocFile(), and MeshCore::MeshOutput::SaveAny().

◆ lastModified()

TimeInfo FileInfo::lastModified ( ) const

Returns the time when the file was last modified.

References exists(), FileName, Base::TimeInfo::null(), Base::TimeInfo::setTime_t(), and toStdWString().

◆ lastRead()

TimeInfo FileInfo::lastRead ( ) const

Returns the time when the file was last read (accessed).

References exists(), FileName, Base::TimeInfo::null(), Base::TimeInfo::setTime_t(), and toStdWString().

◆ pathToString()

std::string FileInfo::pathToString ( const boost::filesystem::path &  p)
static

Convert from filesystem path to string.

◆ renameFile()

bool FileInfo::renameFile ( const char *  NewName)

Rename the file.

References FileName, and toStdWString().

Referenced by App::Document::onChanged(), and App::PropertyFileIncluded::Paste().

◆ setFile() [1/2]

◆ setFile() [2/2]

void Base::FileInfo::setFile ( const std::string &  name)

Set a new file name.

References setFile().

Referenced by setFile().

◆ setPermissions()

◆ size()

unsigned int FileInfo::size ( ) const

◆ stringToPath()

boost::filesystem::path FileInfo::stringToPath ( const std::string &  str)
static

Convert from string to filesystem path.

Referenced by createDirectories().

◆ toStdWString()

Member Data Documentation

◆ FileName


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