当前位置:网站首页>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"边栏推荐
- 融入STEAM教育的劳动技能课程
- Multithreading tool class completabilefuture
- try anbox (by quqi99)
- C language pointer to function
- Unity ar shadow shadow
- Error: GPG check FAILED Once install MySQL
- 力扣每日一题-第30天-1281.整数的各位积和之差
- [deep learning] - maze task learning I (to realize the random movement of agents)
- Easy to understand TCP four waves (multi picture explanation)
- Redistemplate handles hash integer type problem resolution
猜你喜欢

jetson tx2

Creating a new generation of production and service tools with robot education

Sourcetree remote red exclamation point

Delete tag

开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事

用机器人教育创造新一代生产和服务工具

Json对象和Json字符串的区别

解析学习幼儿机器人教育的浪潮

Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- path width style function
![[C language] flexible array](/img/22/3255740602232abfdf69624762adca.jpg)
[C language] flexible array
随机推荐
Why should enterprises do more application activities?
Case of single file component files
Where is the Gcov symbol- Where are the gcov symbols?
mongostat性能分析
It is the only one in China that Alibaba cloud container service has entered the Forrester leader quadrant
Print Yanghui triangle
Convert data frame with date column to timeseries
Li Kou daily question - day 30 -1523 Number of bit 1
Analysis on the wave of learning robot education for children
Principle of screen printing adjustment of EDA (cadence and AD) software
转:侯宏:企业数字化转型的关键不是技术,而是战略
WDCP访问不存在的路径全部跳转到首页不返回404的解决办法
力扣今日题-324. 摆动排序 II
IDEA常用插件
AIRNET notes 1
Vite快速上手
Analysis comp122 the Caesar cipher
Single application and microservice application
Output of character pointer to string in C language
Mongodb paging method