转载:http://blog.sina.com.cn/s/blog_3e62c50d01013xd4.html
QFileInfo的几个构造函数:
QFileInfo
QFileInfo
QFileInfo
QFileInfo
QFileInfo
一般用法:
QFileInfo fileInfo(path);
//or
QFileInfo fileInfo;
fileInfo.setFile(path);
bool
qint64
//路径和文件名相关:
QString
QString
QString
// 例子如下
QFileInfo fileInfo("/home/dipper/xyz.tar.gz");
fileInfo.path(); // returns "/home/dipper"
fileInfo.fileName(); // returns "xyz.tar.gz"
fileInfo.baseName(); // returns "xyz"
fileInfo.completeBaseName(); // returns "xyz.tar"
fileInfo.suffix(); // returns "gz"
fileInfo.completeSuffix(); // returns "tar.gz"
//类型:
bool
bool
bool
//
QString
//日期相关:
QDateTime
QDateTime
QDateTime
//权限:
isReadable(), isWritable(), isExecutable()
//所有者:
ower(), owerId(), group(), groupId(), permissions(),
permission(QFile::Permissions permissions)
dir(): 返回父目录
//下面三个都返回"~/examples/191697"
QFileInfo fileInfo1("~/examples/191697/.");
QFileInfo fileInfo2("~/examples/191697/..");
QFileInfo fileInfo3("~/examples/191697/main.cpp");
//下面三个都返回"."
QFileInfo fileInfo4(".");
QFileInfo fileInfo5("..");
QFileInfo fileInfo6("main.cpp");
//相对路径和绝对路径
QString absolute = "/local/bin";
QString relative = "local/bin";
QFileInfo absFile(absolute);
QFileInfo relFile(relative);