Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Check if directory exists

    General and Desktop
    5
    6
    18870
    Loading More Posts
    • 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.
    • RIVOPICO
      RIVOPICO last edited by

      Hi i do this to check the directory exists:
      if (directorio.exists(Path)){
      and then copy to this directory
      }
      But not Works some solution

      K 1 Reply Last reply Reply Quote 0
      • P
        Paul Colby last edited by

        Hi @RIVOPICO,

        I typically do something like:

            const QFileInfo outputDir("some-directory-path-name");
            if ((!outputDir.exists()) || (!outputDir.isDir()) || (!outputDir.isWritable())) {
                qWarning() << "output directory does not exist, is not a directory, or is not writeable"
                           << outputDir.absoluteFilePath();
                return false;
            }
        

        Cheers.

        1 Reply Last reply Reply Quote 4
        • K
          koahnig @RIVOPICO last edited by

          @RIVOPICO

          you should use this

          QDir pathDir(Path);
          if (pathDir.exists())
          {
          ... do your stuff ...
          }
          

          Vote the answer(s) that helped you to solve your issue(s)

          RIVOPICO 1 Reply Last reply Reply Quote 2
          • RIVOPICO
            RIVOPICO @koahnig last edited by RIVOPICO

            @koahnig i get this message when i do this:
            QIODevice::write (QFile, "PATH"): device not open

            I'm trying to copy one application

            1 Reply Last reply Reply Quote 0
            • ?
              A Former User last edited by

              Have a look at http://doc.qt.io/qt-5/qdir.html. Just like @koahnig said, bool QDir::exists(const QString &name) const and bool QDir::exists() const do different things.

              1 Reply Last reply Reply Quote 3
              • Poorti
                Poorti last edited by

                You can try this..

                QString destPath;
                QString srcPath;
                ......
                ......
                QDir dir(destPath);
                if(dir.exists())
                {
                        // append file name to destPath here
                        ....
                        destPath.append(fileName);
                	if(!QFile::copy(srcPath, destPath))
                	{
                		qDebug() << "Unable to copy file!";
                		....
                	}
                	... copy successful...
                }
                

                Note that, for QFile::copy to work the destination path should contain the name of the file as well.
                eg,

                QFile::copy("C:/work/myfolder/srcFile.txt", "D:/samples/destFile.txt");
                

                will work.

                QFile::copy("C:/work/myfolder/srcFile.txt", "D:/samples");
                

                won't work.

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post