PDA

View Full Version : How to create a symlink to a directory?



ucomesdag
10th January 2007, 06:02
As the title says, does anyone know if there is a easy way to create a symlink to a directory with QT 4.2?
Fore files there is QFile::link(...) but I couldn't find anything for QDir.

It's giving me a headeach...:p

Thanks.

guilugi
10th January 2007, 10:39
Hello,

Well, the QFile::link() method works fine for both files or directories !

Just tried this for example, /home/gfy is my home directory

QFile::link("/home/gfy", "/tmp/mylink");

It creates a link in /tmp, called mylink, and it points to /home/gfy :)

ucomesdag
10th January 2007, 19:58
It works, thanks. But not on windows? :(

guilugi
10th January 2007, 20:06
Well, I don't know, because I was at work, and I have only Debian there...

Maybe it doesn't work, I'll try it tonight

ucomesdag
21st January 2007, 20:01
I should have RTFM!:o Anyway this way it works.


#ifdef Q_OS_UNIX
QFile::link(sourceDir.absolutePath(), destDir.absolutePath());
#endif

#ifdef Q_OS_WIN
QFile::link(sourceDir.absolutePath(), destDir.absolutePath().append(".lnk"));
#endif