PDA

View Full Version : Delete Windows shortcut file



Boron
15th January 2013, 14:00
Hello,

in my application I search for files and the user can select from the found files and delete them.
Now I have the problem that if a file is a Windows shortcut QFile::remove(...) cannot remove the shortcut as it tries to remove the linked file.

E.g.
- C:\theShortcut.html.lnk points to C:\path\someFile.html
- Now I want to delete the shortcut with QFile::remove("C:\theShortcut.html.lnk")
- But now Qt tries to delete C:\path\someFile.html (let us ignore whether the file exists or not)

Is there a way to delete a Windows shortcut file with Qt?

mvuori
16th January 2013, 17:47
I guess this is a Qt bug and there is no workaround in Qt. You may need to resort to a C++ runtime function (unlink(), remove()) or a Windows API function to do the deletion.

amleto
16th January 2013, 21:17
or get boost filesystem which will work on win and *nix.