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::FileInfo > | getDirectoryContent () 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... | |
File name unification This class handles everything related to file names the file names are internal generally UTF-8 encoded on all platforms.
FileInfo::FileInfo | ( | const char * | _FileName = "" | ) |
FileInfo::FileInfo | ( | const std::string & | _FileName | ) |
References setFile().
std::string FileInfo::completeExtension | ( | ) | const |
bool FileInfo::copyTo | ( | const char * | NewName | ) | const |
Rename the file.
References FileName, and toStdWString().
Referenced by TechDraw::DrawUtil::copyFile(), and App::PropertyFileIncluded::Paste().
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().
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().
bool FileInfo::deleteDirectory | ( | ) | const |
Delete an empty directory.
References FileName, isDir(), and toStdWString().
Referenced by deleteDirectoryRecursive().
bool FileInfo::deleteDirectoryRecursive | ( | ) | const |
Delete a directory and all its content.
References deleteDirectory(), getDirectoryContent(), isDir(), and ReadWrite.
Referenced by App::Document::~Document().
bool FileInfo::deleteFile | ( | ) | const |
Delete the file.
References FileName, and toStdWString().
Referenced by StdCmdDuplicateSelection::activated(), Gui::MainWindow::closeEvent(), App::Document::importLinks(), MeshGui::RemeshGmsh::loadOutput(), MeshPartGui::Mesh2ShapeGmsh::loadOutput(), App::PropertyFileIncluded::Paste(), Fem::FemMesh::RestoreDocFile(), Fem::PropertyPostDataObject::RestoreDocFile(), Gui::Application::runApplication(), Fem::FemMesh::SaveDocFile(), and Fem::PropertyPostDataObject::SaveDocFile().
std::string FileInfo::dirPath | ( | ) | const |
Returns the dir path name (which may be absolute or relative).
References FileName.
Referenced by Mesh::AmfExporter::AmfExporter(), Import::ImportOCAF2::ImportOCAF2(), Mesh::MeshObject::load(), App::VRMLObject::onChanged(), App::PropertyFileIncluded::Paste(), App::VRMLObject::RestoreDocFile(), Mesh::MeshObject::save(), Import::ImportOCAF2::setMode(), and App::PropertyFileIncluded::setValue().
bool FileInfo::exists | ( | ) | const |
Does the file exist?
References FileName, and toStdWString().
Referenced by Gui::ViewProviderVRMLObject::addResource(), Mesh::AmfExporter::AmfExporter(), Gui::MainWindow::closeEvent(), App::PropertyFileIncluded::getUniqueFileName(), Part::ImportStepParts(), isDir(), isFile(), lastModified(), lastRead(), MeshCore::MeshInput::LoadAny(), Drawing::FeaturePage::onChanged(), App::Document::onChanged(), Drawing::FeaturePage::onDocumentRestored(), Raytracing::LuxProject::onDocumentRestored(), Raytracing::RayProject::onDocumentRestored(), App::Application::openDocumentPrivate(), App::PropertyFileIncluded::Paste(), Import::StepShape::read(), App::PropertyFileIncluded::RestoreDocFile(), App::PropertyFileIncluded::Save(), MeshCore::MeshOutput::SaveAny(), App::VRMLObject::SaveDocFile(), App::PropertyFileIncluded::setValue(), and Gui::Application::sLoadFile().
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.
References FileName.
Referenced by Gui::Application::exportTo(), Base::Writer::getUniqueFileName(), hasExtension(), Gui::Application::importFrom(), TechDraw::DrawHatch::isBitmapHatch(), TechDraw::DrawHatch::isSvgHatch(), TechDraw::DrawViewSection::makeLineSets(), Gui::Application::open(), App::Application::processCmdLineFiles(), Fem::PropertyPostDataObject::RestoreDocFile(), App::PropertyFileIncluded::setValue(), and Gui::Application::sLoadFile().
std::string FileInfo::fileName | ( | ) | const |
Returns the name of the file, excluding the path, including the extension.
References FileName.
Referenced by Mesh::AmfExporter::AmfExporter(), Drawing::FeaturePage::execute(), TechDraw::DrawSVGTemplate::execute(), fileNamePure(), TechDraw::DrawSVGTemplate::getEditableTextsFromTemplate(), Drawing::FeaturePage::getEditableTextsFromTemplate(), Base::FileException::getFileName(), Base::FileException::getPyObject(), App::VRMLObject::getRelativePath(), Drawing::FeaturePage::onDocumentRestored(), Raytracing::LuxProject::onDocumentRestored(), Raytracing::RayProject::onDocumentRestored(), App::PropertyFileIncluded::Paste(), TechDrawGui::QGSPage::postProcessXml(), and App::PropertyFileIncluded::setValue().
std::string FileInfo::fileNamePure | ( | ) | const |
Returns the name of the file, excluding the path and the extension.
References fileName().
Referenced by Base::Writer::getUniqueFileName(), Part::ImportIgesParts(), Part::ImportStepParts(), App::Application::openDocumentPrivate(), Fem::FemMesh::read(), Gui::Application::sAddCommand(), Mesh::MeshObject::save(), App::Document::saveAs(), App::PropertyFileIncluded::setValue(), and Fem::FemMesh::write().
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().
std::vector< Base::FileInfo > FileInfo::getDirectoryContent | ( | ) | const |
Get a list of the directory content.
References FileInfo(), FileName, and toStdWString().
Referenced by deleteDirectoryRecursive().
|
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().
|
static |
Get the path to the dir which is considered to temp files.
References isDir().
Referenced by getTempFileName().
bool FileInfo::hasExtension | ( | const char * | Ext | ) | const |
Checks for a special extension, NOT case sensitive.
References extension().
Referenced by Fem::FemPostPipeline::canRead(), Gui::View3DInventorViewer::dumpToFile(), MeshCore::MeshInput::getFormat(), Gui::Application::importFrom(), Points::PointsAlgos::Load(), MeshCore::MeshInput::LoadAny(), Gui::Application::open(), Fem::FemPostPipeline::read(), Fem::FemMesh::read(), Part::TopoShape::read(), Part::PropertyPartShape::RestoreDocFile(), Gui::View3DInventorPy::saveVectorGraphic(), Fem::FemMesh::write(), Part::TopoShape::write(), and Gui::SoFCDB::writeToFile().
bool FileInfo::isDir | ( | ) | const |
Checks if it is a directory (not a file)
References exists(), FileName, and toStdWString().
Referenced by deleteDirectory(), deleteDirectoryRecursive(), and getTempPath().
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().
bool FileInfo::isReadable | ( | ) | const |
Checks if the file exist and is readable.
References FileName, and toStdWString().
Referenced by TechDraw::Preferences::bitmapFill(), TechDraw::DrawUtil::copyFile(), TechDraw::Preferences::defaultTemplate(), TechDraw::Preferences::defaultTemplateDir(), Drawing::FeaturePage::execute(), Part::CurveNet::execute(), Part::ImportBrep::execute(), Part::ImportIges::execute(), Part::ImportStep::execute(), Raytracing::LuxProject::execute(), Raytracing::RayProject::execute(), TechDraw::DrawParametricTemplate::execute(), TechDraw::DrawSVGTemplate::execute(), TechDraw::DrawGeomHatch::getDecodedSpecsFromFile(), TechDraw::DrawSVGTemplate::getEditableTextsFromTemplate(), Drawing::FeaturePage::getEditableTextsFromTemplate(), CDxfWrite::getPlateFile(), TechDraw::Preferences::lineGroupFile(), Points::PointsAlgos::Load(), MeshCore::MeshInput::LoadAny(), TechDraw::DrawViewSection::makeLineSets(), TechDraw::DrawTileWeld::onChanged(), TechDraw::DrawViewSection::onChanged(), TechDraw::DrawTileWeld::onDocumentRestored(), TechDraw::DrawGeomHatch::onDocumentRestored(), TechDraw::DrawHatch::onDocumentRestored(), TechDraw::DrawViewSection::onDocumentRestored(), TechDraw::Preferences::patFile(), Fem::FemPostPipeline::read(), Fem::FemMesh::read(), Part::TopoShape::read(), TechDraw::DrawViewImage::setupImageIncluded(), TechDraw::Preferences::svgFile(), and TechDrawGui::PreferencesGui::weldingDirectory().
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().
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().
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().
|
static |
Convert from filesystem path to string.
bool FileInfo::renameFile | ( | const char * | NewName | ) |
Rename the file.
References FileName, and toStdWString().
Referenced by App::Document::onChanged(), and App::PropertyFileIncluded::Paste().
void FileInfo::setFile | ( | const char * | name | ) |
Set a new file name.
References FileName.
Referenced by Drawing::FeaturePage::execute(), TechDraw::DrawSVGTemplate::execute(), FileInfo(), TechDraw::DrawSVGTemplate::getEditableTextsFromTemplate(), Drawing::FeaturePage::getEditableTextsFromTemplate(), Base::Writer::getUniqueFileName(), App::PropertyFileIncluded::getUniqueFileName(), Mesh::MeshObject::load(), Drawing::FeaturePage::onDocumentRestored(), Raytracing::LuxProject::onDocumentRestored(), Raytracing::RayProject::onDocumentRestored(), App::PropertyFileIncluded::Paste(), Mesh::MeshObject::save(), App::VRMLObject::SaveDocFile(), Base::FileException::setFileName(), and App::PropertyFileIncluded::setValue().
void Base::FileInfo::setFile | ( | const std::string & | name | ) |
bool FileInfo::setPermissions | ( | Permissions | perms | ) |
Tries to set the file permission.
References FileName, ReadOnly, toStdWString(), and WriteOnly.
Referenced by App::PropertyFileIncluded::Copy(), App::PropertyFileIncluded::Paste(), App::PropertyFileIncluded::Restore(), and App::PropertyFileIncluded::RestoreDocFile().
unsigned int FileInfo::size | ( | ) | const |
The size of the file.
Referenced by gzip_utf8.GzipFile::close(), PathScripts.PostUtils.GCodeEditorDialog::done(), and gzip_utf8.GzipFile::write().
|
static |
Convert from string to filesystem path.
Referenced by createDirectories().
std::wstring FileInfo::toStdWString | ( | ) | const |
Convert the path name into a UTF-16 encoded wide string format.
References FileName.
Referenced by copyTo(), createDirectory(), deleteDirectory(), deleteFile(), exists(), getDirectoryContent(), isDir(), isFile(), isReadable(), isWritable(), lastModified(), lastRead(), Gui::SoSVGVectorOutput::openFile(), Gui::SoU3DVectorOutput::openFile(), renameFile(), Gui::Application::runApplication(), Base::InterpreterSingleton::runFile(), Gui::PythonDebugger::runFile(), setPermissions(), zipios::ZipFile::ZipFile(), and zipios::ZipInputStream::ZipInputStream().
|
protected |
Referenced by completeExtension(), copyTo(), createDirectories(), createDirectory(), deleteDirectory(), deleteFile(), dirPath(), exists(), extension(), fileName(), filePath(), getDirectoryContent(), getTempFileName(), isDir(), isFile(), isReadable(), isWritable(), lastModified(), lastRead(), renameFile(), setFile(), setPermissions(), and toStdWString().