QT获取文件信息
1:判断文件是否存在:
Static bool QFileInfo::exists(const QString &file)
或者
bool QFileInfo::exists() const
2:获取文件路径
QFileInfo fi(“c:/temp/foo/123.txt”); => fi.absoluteFilePath() =>“C:/temp/foo”
QFileInfo fi(“c:/temp/foo”); => fi.absoluteFilePath() => “C:/temp/foo”
3:获取文件后缀
QFileInfo fi("/tmp/archive.tar.gz");
QString ext = fi.completeSuffix(); // ext = “tar.gz”
QString ext2 = fi.suffix(); // ext2 = “gz”
4:获取文件名:
QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.baseName(); // base = “archive”
QString base2 = fi.completeBaseName(); // base2 = “archive.tar”
QString name = fi.fileName(); // name = “archive.tar.gz”