简体   繁体   English

QT中如何识别项目是文件还是文件夹

[英]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?如何实现这样的 function ,它采用路径(基于QString的输入)并告诉它是文件还是文件夹?

You can use the method QFileInfo::isFile() or QFileInfo::isDir() to accomplish this.您可以使用方法QFileInfo::isFile()QFileInfo::isDir()来完成此操作。

Example :示例

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM