Ejemplo n.º 1
0
bool removeDirectoryRecursively(const QString& Path)
{
  bool Res = true;
  QDir CurrentDir(Path);

  if (CurrentDir.exists(Path))
  {
    for (QFileInfo Info : CurrentDir.entryInfoList(QDir::NoDotAndDotDot |
                                                   QDir::System |
                                                   QDir::Hidden  |
                                                   QDir::AllDirs |
                                                   QDir::Files,
                                                   QDir::DirsFirst))
    {
      if (Info.isDir())
      {
        Res = removeDirectoryRecursively(Info.absoluteFilePath());
      }
      else
      {
        Res = QFile::remove(Info.absoluteFilePath());
      }

      if (!Res)
      {
        return Res;
      }
    }
    Res = CurrentDir.rmdir(Path);
  }

  return Res;
}
Ejemplo n.º 2
0
/**
 * Tries to delete all temporary files and directories whose names were handled out with tempFileName, tempDirectory and createTempDirectory.
 * The deletion of directories is recursive.
 */
void digidoc::util::File::deleteTempFiles() throw(IOException)
{
    while (!tempFiles.empty())
    {
        if ( directoryExists(tempFiles.top()) )
            removeDirectoryRecursively(tempFiles.top());
        else
            removeFile(tempFiles.top());
        tempFiles.pop();
    }
}
Ejemplo n.º 3
0
KmlDocument::~KmlDocument()
{
    foreach( const QString &file, m_files ) {
        if ( !QFile::remove( file ) ) {
            mDebug() << "Failed to remove temporary file" << file;
        }
    }
    if ( !m_path.isEmpty() ) {
        removeDirectoryRecursively( m_path );
    }
}
Ejemplo n.º 4
0
/**
 * Tries to delete this directory along with its contents, recursively.
 *
 * @param dname full directory name
 */
void digidoc::util::File::removeDirectoryRecursively(const std::string& dname) throw(IOException)
{
    // First delete recursively all subdirectories
    std::vector<std::string> subDirs = getDirSubElements(dname, false, false, false);
    for (std::vector<std::string>::reverse_iterator it = subDirs.rbegin(); it != subDirs.rend(); it++)
    {
        removeDirectoryRecursively(*it);
    }

    // Then delete all files inside this directory
    std::vector<std::string> subFiles = getDirSubElements(dname, false, true, false);
    for (std::vector<std::string>::reverse_iterator it = subFiles.rbegin(); it != subFiles.rend(); it++)
    {
        DEBUG( "Deleting the temporary file '%s'", it->c_str() );
        removeFile(*it);
    }

    // Then delete the directory itself. It should now be empty.
    DEBUG( "Deleting the temporary directory '%s'", dname.c_str() );
    removeDirectory(dname);
}
Ejemplo n.º 5
0
bool copyDirectoryRecursively(const QString& SrcPath,
                              const QString& DestPath,
                              const bool DontCopyDotDirs)
{
  bool Res = true;

  QString DestDirPath = DestPath+"/"+QFileInfo(SrcPath).fileName();

  if (QFileInfo(DestDirPath).isDir())
    removeDirectoryRecursively(DestDirPath);

  QDir().mkpath(DestDirPath);

  QDir CurrentDir(SrcPath);

  for (QFileInfo Info : CurrentDir.entryInfoList(QDir::NoDotAndDotDot |
                                                 QDir::System |
                                                 QDir::Hidden  |
                                                 QDir::AllDirs |
                                                 QDir::Files,
                                                 QDir::DirsFirst))
  {
    if (Info.isDir())
    {

      if (!DontCopyDotDirs || (DontCopyDotDirs && !Info.fileName().startsWith(".")))
        Res = copyDirectoryRecursively(Info.absoluteFilePath(), DestDirPath, DontCopyDotDirs);
    }
    else
    {
      Res = QFile::copy(Info.absoluteFilePath(),DestDirPath+"/"+Info.fileName());
    }
  }


  return Res;
}
Ejemplo n.º 6
0
void KmlDocument::removeDirectoryRecursively( const QString &path )
{
    QStringList const subdirs = QDir( path ).entryList( QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot );
    foreach( const QString &subdir, subdirs ) {
        removeDirectoryRecursively( path + '/' + subdir );
    }
Ejemplo n.º 7
0
bool Filesystem::removeDirectory(const std::string& Path)
{
  return removeDirectoryRecursively(QString::fromStdString(Path));
}