Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Copy symbolic link with Qt and xcopy fails
I am writing a backup program that simply copies one folder to another folder and then the next time the backup is run the program compares the two folders and deletes the folders that have been deleted and re-copies over the folders that have been changed. Simple enough of task -- using linux but apparently not windows.
I don't care what is in the folder, eg. hidden files, symbolic links, drives. I want an exact copy, with permissions, dates, etc preserved.
Qt will not let me copy a symbolic link because it is not a file so I will have to re-create it, meaning permissions, dates, etc is not preserved.
Tried using a QProcess to call windows xcopy but there is no proper silent mode where you can just say "get it done" like a "-f" in linux. It always prompts me to see if the destination is a file or directory. One method that apparently works on the command line is to echo F | xcopy .... to tell it that the destination is a file but I cant use pipes in a QProcess and writing a "F\r\n" to the process after it starts doesn't work either for some reason.
Has anybody got a solution to my problem?? I would like to avoid using system calls if I can and just use Qt methods.
Depending on your needs, you should consider using robocopy on windows. It should do for you the job you are describing.
Hope it helps
Thanks for your reply. I will try robocopy. Do you know of a way to treat a symbolic link as a file in Qt so that I can copy it just using qt because I will be running this program on windows and Linux. If it comes to it I suppose I can just have use pre processor comments to specify different builds.
From a pure Qt point of view, I think the best approach would be to check whether the current file is symbolic link, then use QFile::link to recreate it. Check whether it's a relative or absolute link
Thanks for the reply, I worked out my problem and just is case anyone else encounters it I will explain below. If you have a QFile which is set to a symbolic link then the "exists()" method tell you if the file pointed to by the symbolic link exists not if the symbolic link file itself exists. The only way to tell if the file actually exists is to check if it points to something.