Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Copy symbolic link with Qt and xcopy fails
Forum Updated to NodeBB v4.3 + New Features

Copy symbolic link with Qt and xcopy fails

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mitch22
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Depending on your needs, you should consider using robocopy on windows. It should do for you the job you are describing.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mitch22
        wrote on last edited by
        #3

        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.

        Cheers. Mitch.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mitch22
            wrote on last edited by
            #5

            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.

            Cheers

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved