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 Member Functions | |
bool | copyTo (const char *NewName) const |
Rename the file. | |
bool | deleteFile (void) const |
Delete the file. | |
FileInfo (const std::string &_FileName) | |
FileInfo (const char *_FileName="") | |
Constrction. | |
bool | renameFile (const char *NewName) |
Rename the file. | |
void | setFile (const std::string &name) |
Set a new file name. | |
void | setFile (const char *name) |
Set a new file name. | |
Directory management | |
bool | createDirectory (void) const |
Creates a directory. Returns TRUE if successful; otherwise returns FALSE. | |
bool | deleteDirectory (void) const |
Delete an empty directory. | |
bool | deleteDirectoryRecursive (void) const |
Delete a directory and all its content. | |
std::vector< Base::FileInfo > | getDirectoryContent (void) const |
Get a list of the directory content. | |
extraction of information | |
std::string | dirPath () const |
Returns the dir path name (which may be absolute or relative). | |
std::string | extension (bool complete=false) const |
Returns the file's extension name. | |
std::string | fileName () const |
Returns the name of the file, excluding the path, including the extension. | |
std::string | fileNamePure () const |
Returns the name of the file, excluding the path and the extension. | |
std::string | filePath () const |
Returns the file name, including the path (which may be absolute or relative). | |
bool | hasExtension (const char *Ext) const |
Checks for a special extension, NOT case sensetive. | |
std::wstring | toStdWString () const |
Convert the path name into a UCS-2 encoded wide string format. | |
methods to test the status of the file or dir | |
bool | exists () const |
Does the file exist? | |
bool | isDir () const |
Checks if it is a directory (not a file). | |
bool | isFile () const |
Checks if it is a file (not a direrctory). | |
bool | isReadable () const |
Checks if the file exist and is readable. | |
bool | isWritable () const |
Checks if the file exist and is writable. | |
TimeInfo | lastModified () const |
Returns the time when the file was last modified. | |
TimeInfo | lastRead () const |
Returns the time when the file was last read (accessed). | |
unsigned int | size () const |
The size of the file. | |
Static Public Member Functions | |
Tools | |
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. | |
static const std::string & | getTempPath (void) |
Get the path to the dir which is considered to temp files. | |
Protected Attributes | |
std::string | FileName |
File name unification This class handles everything related to file names the file names are internal generally UTF-8 encoded on all platforms.
Definition at line 42 of file FileInfo.h.
FileInfo::FileInfo | ( | const char * | _FileName = "" |
) |
Constrction.
Definition at line 91 of file FileInfo.cpp.
References setFile().
Referenced by getDirectoryContent().
FileInfo::FileInfo | ( | const std::string & | _FileName | ) |
Definition at line 96 of file FileInfo.cpp.
References setFile().
bool FileInfo::copyTo | ( | const char * | NewName | ) | const |
Rename the file.
Definition at line 432 of file FileInfo.cpp.
References draftlibs::dxfLibrary::copy, DrawingExample::file, FileName, and toStdWString().
Referenced by App::PropertyFileIncluded::setValue().
bool FileInfo::createDirectory | ( | void | ) | const |
Creates a directory. Returns TRUE if successful; otherwise returns FALSE.
Definition at line 450 of file FileInfo.cpp.
References FileName, and toStdWString().
Referenced by App::Document::Document().
bool FileInfo::deleteDirectory | ( | void | ) | const |
Delete an empty directory.
Definition at line 462 of file FileInfo.cpp.
References FileName, isDir(), and toStdWString().
Referenced by deleteDirectoryRecursive().
bool FileInfo::deleteDirectoryRecursive | ( | void | ) | const |
Delete a directory and all its content.
Definition at line 475 of file FileInfo.cpp.
References deleteDirectory(), getDirectoryContent(), and isDir().
bool FileInfo::deleteFile | ( | void | ) | const |
Delete the file.
Definition at line 403 of file FileInfo.cpp.
References FileName, and toStdWString().
Referenced by App::PropertyFileIncluded::Copy(), App::DocumentPy::getTempFileName(), App::PropertyFileIncluded::Paste(), Part::PropertyPartShape::RestoreDocFile(), Fem::FemMesh::RestoreDocFile(), App::Document::save(), Part::PropertyPartShape::SaveDocFile(), Fem::FemMesh::SaveDocFile(), and App::PropertyFileIncluded::setValue().
std::string FileInfo::dirPath | ( | ) | const |
Returns the dir path name (which may be absolute or relative).
Definition at line 215 of file FileInfo.cpp.
References FileName.
Referenced by App::PropertyFileIncluded::Copy(), App::PropertyFileIncluded::Paste(), MeshCore::MeshOutput::SaveAny(), and App::PropertyFileIncluded::setValue().
bool FileInfo::exists | ( | ) | const |
Does the file exist?
Definition at line 266 of file FileInfo.cpp.
References FileName, and toStdWString().
Referenced by App::Document::Document(), isDir(), isFile(), lastModified(), lastRead(), MeshCore::MeshInput::LoadAny(), ParameterManager::LoadOrCreateDocument(), App::Application::openDocument(), MeshCore::MeshOutput::SaveAny(), and App::PropertyFileIncluded::setValue().
std::string FileInfo::extension | ( | bool | complete = false |
) | const |
Returns the file's extension name.
If complete is TRUE (the default), extension() returns the string of all characters in the file name after (but not including) the first '.' character. If complete is FALSE, extension() returns the string of all characters in the file name after (but not including) the last '.' character. Example:
FileInfo fi( "/tmp/archive.tar.gz" ); std::string ext = fi.extension(true); // ext = "tar.gz" ext = fi.extension(false); // ext = "gz" ext = fi.extension(); // ext = "gz" *
Definition at line 247 of file FileInfo.cpp.
References FileName, and RobotExample::pos.
Referenced by Gui::Application::exportTo(), Base::Writer::getUniqueFileName(), hasExtension(), Gui::Application::importFrom(), insert(), Points::PointsAlgos::Load(), Gui::Application::open(), open(), App::PropertyFileIncluded::setValue(), and Gui::SoFCOffscreenRenderer::writeToImageFile().
std::string FileInfo::fileName | ( | ) | const |
Returns the name of the file, excluding the path, including the extension.
Definition at line 210 of file FileInfo.cpp.
References FileName.
Referenced by App::PropertyFileIncluded::Copy(), Base::FileException::FileException(), fileNamePure(), and App::PropertyFileIncluded::setValue().
std::string FileInfo::fileNamePure | ( | ) | const |
Returns the name of the file, excluding the path and the extension.
Definition at line 220 of file FileInfo.cpp.
References fileName(), and RobotExample::pos.
Referenced by Base::Writer::getUniqueFileName(), importer(), Part::ImportIgesParts(), Part::ImportStepParts(), insert(), open(), App::Application::openDocument(), Fem::FemMesh::read(), and App::PropertyFileIncluded::setValue().
std::string FileInfo::filePath | ( | ) | const |
Returns the file name, including the path (which may be absolute or relative).
Definition at line 205 of file FileInfo.cpp.
References FileName.
Referenced by App::PropertyFileIncluded::Copy(), Gui::MainWindow::createMimeDataFromSelection(), App::Document::Document(), Gui::Application::exportTo(), App::DocumentPy::getTempFileName(), Gui::Application::importFrom(), ParameterManager::LoadDocument(), Gui::Application::open(), App::Application::openDocument(), Gui::SoU3DVectorOutput::openFile(), Gui::SoSVGVectorOutput::openFile(), Part::TopoShape::read(), Fem::FemMesh::read(), Part::PropertyPartShape::RestoreDocFile(), Fem::FemMesh::RestoreDocFile(), App::Document::save(), Part::PropertyPartShape::SaveDocFile(), Fem::FemMesh::SaveDocFile(), ParameterManager::SaveDocument(), App::PropertyFileIncluded::setValue(), Part::TopoShape::write(), Fem::FemMesh::write(), and Base::XMLReader::XMLReader().
std::vector< Base::FileInfo > FileInfo::getDirectoryContent | ( | void | ) | const |
Get a list of the directory content.
Definition at line 491 of file FileInfo.cpp.
References FileInfo(), FileName, and toStdWString().
Referenced by deleteDirectoryRecursive().
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.
Definition at line 133 of file FileInfo.cpp.
References DrawingExample::file, and getTempPath().
Referenced by App::PropertyFileIncluded::Copy(), Gui::MainWindow::createMimeDataFromSelection(), App::PropertyFileIncluded::getExchangeTempFile(), App::DocumentPy::getTempFileName(), Gui::View3DInventor::print(), Part::PropertyPartShape::RestoreDocFile(), Fem::FemMesh::RestoreDocFile(), Part::PropertyPartShape::SaveDocFile(), Fem::FemMesh::SaveDocFile(), and App::PropertyFileIncluded::setValue().
const std::string & FileInfo::getTempPath | ( | void | ) | [static] |
Get the path to the dir which is considered to temp files.
Definition at line 101 of file FileInfo.cpp.
References isDir().
Referenced by App::Document::Document(), getTempFileName(), and App::Document::Restore().
bool FileInfo::hasExtension | ( | const char * | Ext | ) | const |
Checks for a special extension, NOT case sensetive.
Definition at line 257 of file FileInfo.cpp.
References extension().
Referenced by Gui::View3DInventorViewer::dumpToFile(), exporter(), importer(), Gui::Application::importFrom(), insert(), MeshCore::MeshInput::LoadAny(), Gui::Application::open(), open(), Part::TopoShape::read(), Fem::FemMesh::read(), MeshCore::MeshOutput::SaveAny(), Gui::View3DInventorPy::saveVectorGraphic(), Part::TopoShape::write(), Fem::FemMesh::write(), and Gui::SoFCOffscreenRenderer::writeToImageFile().
bool FileInfo::isDir | ( | ) | const |
Checks if it is a directory (not a file).
Definition at line 321 of file FileInfo.cpp.
References exists(), FileName, and toStdWString().
Referenced by deleteDirectory(), deleteDirectoryRecursive(), and getTempPath().
bool FileInfo::isFile | ( | ) | const |
Checks if it is a file (not a direrctory).
Definition at line 296 of file FileInfo.cpp.
References exists(), FileName, and toStdWString().
Referenced by MeshCore::MeshInput::LoadAny().
bool FileInfo::isReadable | ( | ) | const |
Checks if the file exist and is readable.
Definition at line 276 of file FileInfo.cpp.
References FileName, and toStdWString().
Referenced by Part::ImportStepParts(), Points::PointsAlgos::Load(), MeshCore::MeshInput::LoadAny(), Part::TopoShape::read(), Fem::FemMesh::read(), App::DocumentPy::restore(), and App::DocumentPy::save().
bool FileInfo::isWritable | ( | ) | const |
Checks if the file exist and is writable.
Definition at line 286 of file FileInfo.cpp.
References FileName, and toStdWString().
Referenced by MeshCore::MeshOutput::SaveAny().
TimeInfo FileInfo::lastModified | ( | ) | const |
Returns the time when the file was last modified.
Definition at line 357 of file FileInfo.cpp.
References exists(), FileName, Base::TimeInfo::null(), Base::TimeInfo::setTime_t(), and toStdWString().
Referenced by App::Document::save().
TimeInfo FileInfo::lastRead | ( | ) | const |
Returns the time when the file was last read (accessed).
Definition at line 380 of file FileInfo.cpp.
References exists(), FileName, Base::TimeInfo::null(), Base::TimeInfo::setTime_t(), and toStdWString().
bool FileInfo::renameFile | ( | const char * | NewName | ) |
Rename the file.
Definition at line 415 of file FileInfo.cpp.
References FileName, setFile(), and toStdWString().
Referenced by App::PropertyFileIncluded::Copy(), App::PropertyFileIncluded::Paste(), App::Document::save(), and App::PropertyFileIncluded::setValue().
void Base::FileInfo::setFile | ( | const std::string & | name | ) | [inline] |
Set a new file name.
Definition at line 51 of file FileInfo.h.
References setFile().
Referenced by setFile().
void FileInfo::setFile | ( | const char * | name | ) |
Set a new file name.
Definition at line 185 of file FileInfo.cpp.
References FileName, and result.
Referenced by FileInfo(), Base::Writer::getUniqueFileName(), renameFile(), and App::PropertyFileIncluded::setValue().
unsigned int FileInfo::size | ( | ) | const |
The size of the file.
Definition at line 350 of file FileInfo.cpp.
std::wstring FileInfo::toStdWString | ( | ) | const |
Convert the path name into a UCS-2 encoded wide string format.
Definition at line 231 of file FileInfo.cpp.
References FileName.
Referenced by copyTo(), createDirectory(), deleteDirectory(), deleteFile(), exists(), getDirectoryContent(), isDir(), isFile(), isReadable(), isWritable(), lastModified(), lastRead(), ParameterManager::LoadDocument(), Gui::SoU3DVectorOutput::openFile(), Gui::SoSVGVectorOutput::openFile(), renameFile(), Base::InterpreterSingleton::runFile(), ParameterManager::SaveDocument(), and Gui::SoFCOffscreenRenderer::writeToImageFile().
std::string Base::FileInfo::FileName [protected] |
Definition at line 132 of file FileInfo.h.
Referenced by copyTo(), createDirectory(), deleteDirectory(), deleteFile(), dirPath(), exists(), extension(), fileName(), filePath(), getDirectoryContent(), isDir(), isFile(), isReadable(), isWritable(), lastModified(), lastRead(), renameFile(), setFile(), and toStdWString().