PDA

View Full Version : How to retrieve the actual size of a symlink/shortcut?



dobedidoo
30th January 2017, 14:27
Hi,

I'm trying to retrieve the size of a symlink/shortcut (.lnk in Windows) using QFileInfo::size(), but I always end up getting the size of the target of the shortcut.

Assume I have a file 'C:\Temp\testfile.txt' which is of size 653 bytes. Also, I have a shortcut 'testfile.txt.lnk' pointing to the text file. According to Windows, the size of the shortcut (.lnk) is 851 bytes in my case. How shall I do to find this size (851 bytes) with Qt using the path of the shortcut?

Like I said, I thought QFileInfo::size() would to that, but the following example shows that this is not the case (at least not for me):


QFileInfo info1("C:\\Temp\\testfile.txt.lnk");
qDebug() << info1.isSymLink();
qDebug() << info1.absoluteFilePath();
qDebug() << info1.size() << "!!!!! should be 851!";
qDebug() << info1.symLinkTarget();
qDebug() << "-----------------";
QFileInfo info2 = QFileInfo(info1.symLinkTarget());
qDebug() << info2.isSymLink();
qDebug() << info2.absoluteFilePath();
qDebug() << info2.size();
Output from this test is

true
"C:/Temp/testfile.txt.lnk"
653 "!!!!! should be 851!"
"C:/Temp/testfile.txt"
-----------------
false
"C:/Temp/testfile.txt"
653

I use Qt 5.7.0 in Windows.

Grateful for any help.