Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't copy Directory from Windows system even after i give admin to my app
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 848 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2
      • don't use foreach (https://www.kdab.com/goodbye-q_foreach/)
      • Check that dst + QDir::separator() + f does not exist before copying
      • What does QFile::copy return?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • AmrCoderA Offline
        AmrCoderA Offline
        AmrCoder
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

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

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          3
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by VRonin
            #5

            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));
                }
            }
            

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            2
            • AmrCoderA Offline
              AmrCoderA Offline
              AmrCoder
              wrote on last edited by
              #6

              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);
              
              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved