Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Weird ::CopyFile problem

Weird ::CopyFile problem

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestionannouncement
8 Posts 3 Posters 0 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.
  • O Offline
    O Offline
    od ananzi co za
    wrote on last edited by
    #1

    I have an application that upon startup does an automatic software update. It checks a folder if it contains any files, and if found, copies those files over to their respective target folders. Now suddenly this updating does not work anymore. It copies the file to the target folder, but the result is not a file in the target folder, but a sub folder with it's name as the source file's name. Ex. I have a file in my upgrade folder: C:\Program\Upg\Logo.jpg This file needs to be copied to C:\Program So my program does CopyFile(strSource, strTarget, FALSE) with strSource = "C:\\Program\\Upg\\Logo.jpg" strTarget = "C:\\Program\\Logo.jpg" After the copy I end up with a sub-folder in C:\Program called Logo.jpg\ which is empty, instead of a file called Logo.jpg in C:\Program I then hard coded the paths like: CopyFile("C:\\Program\\Upg\\Logo.jpg", "C:\\Program\\Logo.jpg", FALSE); but it does exactly the same I then made an empty new console application with the hard coded CopyFile call as above and it works fine, ie. Logo.jpg is copied from the Upg folder to C:\Program I tried playing with the project settings, stack/heap sizes, etc, but my application does not copy the file ! Any ideas ?

    S 1 Reply Last reply
    0
    • O od ananzi co za

      I have an application that upon startup does an automatic software update. It checks a folder if it contains any files, and if found, copies those files over to their respective target folders. Now suddenly this updating does not work anymore. It copies the file to the target folder, but the result is not a file in the target folder, but a sub folder with it's name as the source file's name. Ex. I have a file in my upgrade folder: C:\Program\Upg\Logo.jpg This file needs to be copied to C:\Program So my program does CopyFile(strSource, strTarget, FALSE) with strSource = "C:\\Program\\Upg\\Logo.jpg" strTarget = "C:\\Program\\Logo.jpg" After the copy I end up with a sub-folder in C:\Program called Logo.jpg\ which is empty, instead of a file called Logo.jpg in C:\Program I then hard coded the paths like: CopyFile("C:\\Program\\Upg\\Logo.jpg", "C:\\Program\\Logo.jpg", FALSE); but it does exactly the same I then made an empty new console application with the hard coded CopyFile call as above and it works fine, ie. Logo.jpg is copied from the Upg folder to C:\Program I tried playing with the project settings, stack/heap sizes, etc, but my application does not copy the file ! Any ideas ?

      S Offline
      S Offline
      ShilpiP
      wrote on last edited by
      #2

      is your CopyFile return true or false?? If false than use GetLastError() to check the error information.

      "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."

      O 2 Replies Last reply
      0
      • S ShilpiP

        is your CopyFile return true or false?? If false than use GetLastError() to check the error information.

        "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."

        O Offline
        O Offline
        od ananzi co za
        wrote on last edited by
        #3

        It sometimes returns TRUE , but still copies the file into the empty sub-folder It sometimes returns FALSE, but still copies the file into the empty sub-folder, GetLastError then returns 5

        S 1 Reply Last reply
        0
        • S ShilpiP

          is your CopyFile return true or false?? If false than use GetLastError() to check the error information.

          "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."

          O Offline
          O Offline
          od ananzi co za
          wrote on last edited by
          #4

          I have now also tried SHFileOperation as follows, but it also copies the file into the sub folder : SHFILEOPSTRUCT sMove = {GetSafeHwnd(), FO_MOVE}; sMove.pFrom = strSource + _T("\0"); sMove.pTo = strTarget + _T("\0"); sMove.fFlags = FOF_NO_UI; SHFileOperation(&sMove);

          1 Reply Last reply
          0
          • O od ananzi co za

            It sometimes returns TRUE , but still copies the file into the empty sub-folder It sometimes returns FALSE, but still copies the file into the empty sub-folder, GetLastError then returns 5

            S Offline
            S Offline
            ShilpiP
            wrote on last edited by
            #5

            od@ananzi.co.za wrote:

            It sometimes returns TRUE , but still copies the file into the empty sub-folder
            It sometimes returns FALSE, but still copies the file into the empty sub-folder, GetLastError then returns 5

            :confused: If GetLastError returns 5 than it means Access Denied. You do not have rights to copy data in Program folder. 1) Run your application as admin or 2) Change the property "UAC Execution Level" -> "asInvoker" to "requireAdministrator".

            "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."

            O 1 Reply Last reply
            0
            • S ShilpiP

              od@ananzi.co.za wrote:

              It sometimes returns TRUE , but still copies the file into the empty sub-folder
              It sometimes returns FALSE, but still copies the file into the empty sub-folder, GetLastError then returns 5

              :confused: If GetLastError returns 5 than it means Access Denied. You do not have rights to copy data in Program folder. 1) Run your application as admin or 2) Change the property "UAC Execution Level" -> "asInvoker" to "requireAdministrator".

              "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."

              O Offline
              O Offline
              od ananzi co za
              wrote on last edited by
              #6

              It made no difference. I also tried running the program as Administrator, but still the same. Remember that my console application worked fine though, so I doubt that it is permissions ...

              S S 2 Replies Last reply
              0
              • O od ananzi co za

                It made no difference. I also tried running the program as Administrator, but still the same. Remember that my console application worked fine though, so I doubt that it is permissions ...

                S Offline
                S Offline
                ShilpiP
                wrote on last edited by
                #7

                Error code 5 means access denied. I am not sure why this error comes. I don't know it is working or not but before copying the file into the target file, Delete the target file using "DeleteFile".

                 DeleteFile(strTargetPath);
                 CopyFile(strSourcePath,strTargetPath,FALSE);	
                

                "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."

                1 Reply Last reply
                0
                • O od ananzi co za

                  It made no difference. I also tried running the program as Administrator, but still the same. Remember that my console application worked fine though, so I doubt that it is permissions ...

                  S Offline
                  S Offline
                  smags13
                  wrote on last edited by
                  #8

                  Hi, I'm not 100% sure, but it might be caused by UNICODE-related settings. Make sure your call to CopyFile is actually using CopyFileW. Also, you can check your compiler command line to see if it uses UNICODE option.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups