QFileInfo獲取檔案資訊

2021-07-29 20:36:55 字數 2235 閱讀 7837

簡述:

qfileinfo類提供了關於檔名,檔案路徑,訪問許可權等相關檔案資訊。

qfileinfo

fileinfo(path);

//or

qfileinfo

fileinfo;

fileinfo.setfile(path);

bool

exists();

//判斷檔案是否存在,若存在返回true

qint64

size();

//獲取檔案大小,返回bytes

//路徑和檔名相關:

qstring

path();

//返回檔案路徑,不包含檔名

qstring

filepath();

//返回檔案路徑,包含檔名

qstring

filename();

//返回檔名稱

qstring

suffix();

//返回字尾名稱

//型別:

bool

isfile();

//判斷是否是檔案

bool

isdir();

//判斷是否是路徑

bool

issymlink();

//判斷是否是符號鏈結

//

qstring

symlinktarget();//返回符號鏈結的檔案

//日期相關:

qdatetime

created();

//建立時間

qdatetime

lastmodified();

//最近修改時間

qdatetime

lastread();

//最近讀時間

//許可權:

bool

isreadable();

//判斷是否可讀

bool

iswritable();

//判斷是否可寫

bool

i***ecutable();

//判斷是否可執行

//所有者:

qstring

ower();

//返回檔案所有者,若出現錯誤,返回空字串

uint

owerid();

//返回檔案所有者id

qstring

group();

//返回檔案的group,若出現錯誤,返回空字串

uint

groupid();

//返回檔案所屬組的id

qfile::permissions

permissions();//返回檔案許可權

bool

qfileinfo::permission(qfile::permissions

permissions);

//試驗檔案的許可權

qdir

dir();

//返回父目錄

qfileinfo

fileinfo("/home/hebbe/xyz.tar.gz");

if(fileinfo.exists())

QT使用QFileInfo類來獲取檔案資訊

在qt中為檔案的操作和資訊獲取提供了許多方便的類,常用的有qdir,qfile,qfileinfo以及qfiledialog。qfileinfo類提供了關於檔名,檔案路徑,訪問許可權等相關檔案資訊。qfileinfo可以提供檔案的名稱和位置資訊,此外,還有檔案的大小,檔案的訪問許可權以及此檔案是不是...

獲取檔案資訊

include struct stat 函式宣告 int stat const char path,struct stat buffer 注意 win32 stat linux stat 引數 path 檔案或者資料夾的路徑 buffer 獲取的資訊儲存在記憶體中 返回值 正確 返回0 錯誤 返回 ...

獲取檔案版本資訊

ref copy char szfilename c windows system32 cmd.exe dword dwsize getfileversioninfosize szfilename,null lpvoid pblock malloc dwsize getfileversioninfo...