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. Check if directory exists

Check if directory exists

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 23.5k Views
  • 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.
  • RIVOPICOR Offline
    RIVOPICOR Offline
    RIVOPICO
    wrote on last edited by
    #1

    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
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      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
      4
      • RIVOPICOR RIVOPICO

        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 Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        @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)

        RIVOPICOR 1 Reply Last reply
        3
        • K koahnig

          @RIVOPICO

          you should use this

          QDir pathDir(Path);
          if (pathDir.exists())
          {
          ... do your stuff ...
          }
          
          RIVOPICOR Offline
          RIVOPICOR Offline
          RIVOPICO
          wrote on last edited by RIVOPICO
          #4

          @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
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            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
            3
            • PoortiP Offline
              PoortiP Offline
              Poorti
              wrote on last edited by
              #6

              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
              1

              • Login

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