Can't copy Directory from Windows system even after i give admin to my app



  • Hello,
    I create an app that takes a copy of a Directory on C drive windows system to another folder when I work with windows system I give my app admin using this way here.
    i use this code to copy the folder with all it's content.
    this function.

    void MainWindow::copyPath(QString src, QString dst)
    {
        QDir dir(src);
        if (! dir.exists())
            return;
    
        foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
            QString dst_path = dst + QDir::separator() + d;
            dir.mkpath(dst_path);
            copyPath(src+ QDir::separator() + d, dst_path);
        }
    
        foreach (QString f, dir.entryList(QDir::Files)) {
            QFile::copy(src + QDir::separator() + f, dst + QDir::separator() + f);
        }
    }
    

    and in the button

    copyPath("C:/Windows/System32/spp/store", "D:/copyfolder");
    

    when i test on another folder on D drive it worked so what i can do so that i make my qt app copy the folder from the C drive.
    Thanks in advance





  • when i give it this path

    C:/Windows/System32/spp/
    

    it copy only one folder which is

    C:/Windows/System32/spp/tokens
    

    and the other folders not copied when i give it the path

    C:/Windows/System32/spp/store
    

    it can't path this condition

        QDir dir(src);
        if (! dir.exists())
            return;
    

    it can't recognize directory



  • both dir.mkpath and QFile::copy return a bool. Could you check if they return true?



  • Try:

    void MainWindow::copyPath(const QString& src, const QString& dst)
    {
        QDir dir(src);
        if (! dir.exists())
            return;
    QDir destDir(dst);
            if(!destDir.exists())
                destDir.mkpath(dst);
    auto entryList = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
        for(QString d : qAsConst(entryList)) {
            Q_ASSUME(destDir.mkdir(d));
            copyPath(src+ QDir::separator() + d, dst + QDir::separator() + d);
        }
    entryList = dir.entryList(QDir::Files);
        for (QString f: qAsConst(entryList)) {
            Q_ASSUME(QFile::copy(src + QDir::separator() + f, dst + QDir::separator() + f));
        }
    }
    


  • sorry for the late reply, i test the function and the same problem i think the problem is in this folder type i don't know why also i tried to check by adding this in the copyPath function and it output YES i not exists.

        QDir dir(src);
        if (! dir.exists()) {
            qDebug() << "YES i not exists";
            return;
        }
    

    the folder i want to copy here

    copyPath("C:/Windows/System32/spp/store", newPath);
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.