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. [SOLVED] QDir::exists(const QString & name) and dirs
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QDir::exists(const QString & name) and dirs

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 7.7k 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.
  • T Offline
    T Offline
    tucnak
    wrote on last edited by
    #1

    Dirs. Is this function will work with them or only with files. If no, how can I review exists of dir.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vezprog
      wrote on last edited by
      #2

      If you want to know if a file exists use,

      @
      #include <QFile>

      bool return;

      QFile filename("location/of/file");
      return = filename.exists();
      if(return == true){
      // success
      }
      else{
      // failed
      }
      @

      I would assume QDir would be the same way...aka replace QFile with QDir.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        [quote author="tucnak" date="1325541840"]Dirs. Is this function will work with them or only with files. If no, how can I review exists of dir.[/quote]

        Instead of asking and waiting for someone to answer, you could just try it yourself. Should be manageable to create this code independently:

        @
        qDebug() << "existing dir: " << QDir("/path/to/existing/dir-or-file").exists();
        qDebug() << "missing dir: " << QDir("/path/to/non-existing/dir-or-file").exists();
        @

        For further research: QFileInfo, including exists(), isDir(), isFile().

        You could have stumbled over this class by reading [[Doc:QDir]] API docs. It's mentioned in the "See also" section and even at the description of QDir::exists(). Is it really that hard to click on the link?

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tucnak
          wrote on last edited by
          #4

          Thanks, Volker. It was informative.

          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