当前位置:网站首页>Qt QFileInfo简介
Qt QFileInfo简介
2022-06-29 06:37:00 【Mr.codeee】
1.简介
QFileInfo类提供与系统无关的文件信息,QFileInfo提供了关于文件的名称和在文件系统中的位置(路径)、它的访问权限以及它是目录还是符号链接等信息。文件的大小和最后修改/读取时间也可用。
2.常用方法
1.如果该对象指向目录或指向目录的符号链接,则返回true;否则返回false。
bool isDir() const
2.如果该对象指向文件或指向文件的符号链接,则返回true。如果对象指向的不是文件,比如目录,则返回false。
bool isFile() const
3.如果这是一个“隐藏”文件,则返回true;否则返回false。
bool isHidden() const
4.如果该对象指向符号链接,则返回true;否则返回false。
bool isSymLink() const
5.返回符号链接指向的文件或目录的绝对路径,如果对象不是符号链接,则返回空字符串。
QString symLinkTarget() const
6.返回文件的后缀(扩展名)。
QString suffix() const
7.返回文件的完整后缀(扩展名)。
QString completeSuffix() const
8.返回文件的名称(不包括路径)。
QString fileName() const
9.返回文件的基本名称,不包含路径。
QString baseName() const
10.返回文件名,包括路径(可以是绝对的或相对的)。
QString filePath() const
11.返回包含文件名的绝对路径。
QString absoluteFilePath() const
12.返回文件的路径。这不包括文件名。
QString path() const
13.以字节为单位返回文件大小。如果文件不存在或无法获取,则返回0。
qint64 size() const
14.返回文件创建/生成的日期和时间。
QDateTime birthTime() const
15.返回文件最后修改的日期和本地时间。
QDateTime lastModified() const
3.示例
1.链接文件
//linux
QFileInfo info1("/home/bob/bin/untabify");
info1.isSymLink(); // returns true
info1.absoluteFilePath(); // returns "/home/bob/bin/untabify"
info1.size(); // returns 56201
info1.symLinkTarget(); // returns "/opt/pretty++/bin/untabify"
//windows
QFileInfo info1("C:\\Documents and Settings\\Bob\\untabify.lnk");
info1.isSymLink(); // returns true
info1.absoluteFilePath(); // returns "C:/Documents and Settings/Bob/untabify.lnk"
info1.size(); // returns 743
info1.symLinkTarget(); // returns "C:/Pretty++/untabify"2.baseName()
QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.baseName(); // base = "archive"3.absoluteFilePath()
QFileInfo fi("c:/temp/foo"); => fi.absoluteFilePath() => "C:/temp/foo"4.文件后缀
QFileInfo fi("/tmp/archive.tar.gz");
QString ext = fi.completeSuffix(); // ext = "tar.gz"
QString ext1 = fi.suffix(); // ext = "gz"5.文件信息
QFileInfo fileInfo("F:\\data.txt");
qDebug()<<"baseName = "<<fileInfo.baseName();
qDebug()<<"fileName = "<<fileInfo.fileName();
qDebug()<<"absoluteFilePath = "<<fileInfo.absoluteFilePath();
qDebug()<<"filePath = "<<fileInfo.filePath();
qDebug()<<"path = "<<fileInfo.path();
qDebug()<<"size = "<<fileInfo.size();
qDebug()<<"birthTime = "<<fileInfo.birthTime().toString("yyyy-MM-dd hh:mm:ss");
qDebug()<<"lastModified = "<<fileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss");
//baseName = "data"
//fileName = "data.txt"
//absoluteFilePath = "F:/data.txt"
//filePath = "F:/data.txt"
//path = "F:/"
//size = 315
//birthTime = "2021-02-23 21:54:13"
//lastModified = "2021-02-23 22:29:06"边栏推荐
- Move disassembly of exclusive delivery of script (the first time)
- Introduction to Ceres Quartet
- Fault: display Storport driver out of date in component health
- Analysis comp122 the Caesar cipher
- 力扣每日一题-第30天-1281.整数的各位积和之差
- 把多个ROC曲线画在一张图上
- Small program large screen adaptation Guide
- QT (x): control operation
- package. Are you familiar with all configuration items and their usage of JSON
- Servlet version conflict causes page 404
猜你喜欢

Fault: KDC warning log for id29

Open source 23 things shardingsphere and database mesh have to say

MySQL learning notes

The annual technology inventory of cloud primitives was released, and it was the right time to ride the wind and waves

Qt 程序打包发布-windeployqt工具

Fresnel diffraction with rectangular aperture based on MATLAB

Json tobean

National Defense University project summary

Principle of screen printing adjustment of EDA (cadence and AD) software

Servlet version conflict causes page 404
随机推荐
Baidu applet automatically submits search
Why should enterprises do more application activities?
Monitor employee turnover dynamics. This system makes employees tremble!
Some thoughts on port forwarding program
二叉树的迭代法前序遍历的两种方法
VerilogA——动态比较器
Unity ar shadow shadow
Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- multi axis mirroring function
Yyds dry goods inventory meituan's two-sided experience, and finally there was a surprise?
[MySQL technology topic] technical analysis and guide for analyzing the high availability architecture of MySQL
json tobean
Ribbon service invocation and load balancing
Teach you how to develop your own NPM package (publish to the NPM official website)
Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- path width style function
想请教一下,究竟有哪些劵商推荐?在线开户是安全么?
Can I cast int to a variable of type byte? What happens if the value is larger than the range of byte type?
Antd work item memo w3.0
After “Go to Definition”, is there a command to return to where you came from?
Configuring the flutter development environment
2022.02.15