判断path是文件夹,文件,还是不存在

参考:

Qt:正确判断文件、文件夹是否存在的方法_qt判断文件夹是否存在-CSDN博客

非常感谢大佬的文章!!! 

实验:

    //D:/aA:存在
    //D:/a:不存在
    //D:/1/1.txt:存在
    //D:/1/2.txt:不存在

    QFileInfo info("D:/aA");
    qDebug()<<info.isDir();
    QFileInfo info1("D:/a");
    qDebug()<<info1.isDir();
    QFileInfo info2("D:/1/1.txt");
    qDebug()<<info2.isFile();
    QFileInfo info3("D:/1/2.txt");
    qDebug()<<info3.isFile();

结果:

true

false

true

false

总结: 

(1)想知道path存不存在,无所谓是文件还是文件夹

QFileInfo::exists()

(2)想知道path是不是文件夹

QFileInfo::isDir()

(3)想知道path是不是文件

QFileInfo::isFile()

猜你喜欢

转载自blog.csdn.net/weixin_51883798/article/details/134879091