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 UCS-2 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 sensetive. 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 (void) const
 Creates a directory. Returns true if successful; otherwise returns false. More...
 
std::vector< Base::FileInfogetDirectoryContent (void) const
 Get a list of the directory content. More...
 
bool deleteDirectory (void) const
 Delete an empty directory. More...
 
bool deleteDirectoryRecursive (void) const
 Delete a directory and all its content. More...
 
bool deleteFile (void) 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=0, const char *path=0)
 Get a unique File Name in the given or (if 0) in the temp path. More...
 
static const std::string & getTempPath (void)
 Get the path to the dir which is considered to temp files. 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"
FileInfo(const char *_FileName="")
Construction.
Definition: FileInfo.cpp:103
ext
Definition: Mesh2Shape.py:17

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().

◆ createDirectory()

bool FileInfo::createDirectory ( void  ) const

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

References FileName, and toStdWString().

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

◆ deleteDirectory()

bool FileInfo::deleteDirectory ( void  ) const

Delete an empty directory.

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

Referenced by deleteDirectoryRecursive().

◆ deleteDirectoryRecursive()

bool FileInfo::deleteDirectoryRecursive ( void  ) 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

Returns the extension of the file.

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

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

References FileName.

Referenced by Gui::Application::exportTo(), Base::Writer::getUniqueFileName(), hasExtension(), Gui::Application::importFrom(), TechDraw::DrawViewSection::makeLineSets(), Gui::Application::open(), App::Application::processCmdLineFiles(), Fem::PropertyPostDataObject::RestoreDocFile(), App::PropertyFileIncluded::setValue(), and Gui::Application::sLoadFile().

◆ 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::PropertyFileIncluded::Copy(), Gui::MainWindow::createMimeDataFromSelection(), TechDraw::DrawViewSymbolPy::dumpSymbol(), Drawing::FeaturePage::execute(), Raytracing::LuxProject::execute(), Raytracing::RayProject::execute(), TechDraw::DrawSVGTemplate::execute(), Gui::Application::exportTo(), WebGui::FcCookieJar::FcCookieJar(), TechDraw::DrawSVGTemplate::getEditableTextsFromTemplate(), Drawing::FeaturePage::getEditableTextsFromTemplate(), CDxfWrite::getPlateFile(), App::DocumentPy::getTempFileName(), 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(), Part::PropertyPartShape::RestoreDocFile(), Gui::Application::sAddCommand(), App::PropertyFileIncluded::Save(), Fem::FemMesh::SaveDocFile(), Fem::PropertyPostDataObject::SaveDocFile(), Part::PropertyPartShape::SaveDocFile(), App::PropertyFileIncluded::setValue(), Fem::FemMesh::write(), Part::TopoShape::write(), and MeshGui::RemeshGmsh::writeProject().

◆ getDirectoryContent()

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

Get a list of the directory content.

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

Referenced by deleteDirectoryRecursive().

◆ getTempFileName()

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

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

References FileName, and getTempPath().

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

◆ getTempPath()

const std::string & FileInfo::getTempPath ( void  )
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().

◆ 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

◆ toStdWString()

Member Data Documentation

◆ FileName


The documentation for this class was generated from the following files:
  • Sources/FreeCAD/src/Base/FileInfo.h
  • Sources/FreeCAD/src/Base/FileInfo.cpp