[英]Convert short/dos style path name to full path name
標題說明了一切。 我已經看到很多解決方案來執行oposite操作但不是這種方式。
我正在使用Qt創建一個臨時文件。 如果我得到它的名字,它將是以下類似的東西:
QTemporaryFile tempFile;
tempFile.open();
qDebug() << tempFile.fileName();
// C:/Users/USERNA~1/AppData/Local/Temp/qt_temp.Hp4264
我嘗試了一些解決方案,比如使用QFileInfo:
QFileInfo fileInfo(tempFile);
qDebug() << fileInfo.filePath()
和QDir:
QDir dir(tempFile.fileName());
qDebug() << dir.absolutePath();
沒有成功。
使用純Qt有沒有解決方案? 我知道我可以瀏覽目錄樹以查找全名,但我試圖避免這種情況,特別是因為兩個文件夾可能有相同的前綴。
win32函數GetLongPathName是你的答案。
QString shortPath = tempFile.fileName();
int length = GetLongPathNameW(shortPath.utf16(),0,0);
wchar_t* buffer = new wchar_t[length];
length = GetLongPathNameW(shortPath.utf16(), buffer, length);
QString fullpath = QString::fromUtf16(buffer, length);
delete[] buffer;
沒有純粹的Qt功能,因為只有Windows這樣做(而且Qt是可移植的)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.