c++qtqdirqfileinfo

How to identify whether an item is a file or a folder in QT


I wanted to specify from a path, whether the item is a file or a folder. How can I implement such function which takes a path (QString based input) and tells whether it is a file or folder?


Solution

  • You can use the method QFileInfo::isFile() or QFileInfo::isDir() to accomplish this.

    Example:

    QFileInfo fi("/your/path/string");
    if (fi.exists() && fi.isFile())
    {
       //Do stuff...
    }