2

I'm using MoveFileEx to move a file. depending on what the user inputs, where it moves the files might be on a seperate hard drive. under this circumstance MoveFileEx fails with GetLastError reporting error ID 17, which is:

ERROR_NOT_SAME_DEVICE 17 (0x11) The system cannot move the file to a different disk drive. (http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx)

so, how, in VC++ would I go about handling a situation like this, and move the file, even if it's on a seperate hard drive?

the code I'm using is here: https://gist.github.com/Whitetigerswt/9180030 (although it's not relevant I think, everything works great except when moving files to another hard drive.)

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user1239109
  • 31
  • 1
  • 2

1 Answers1

12

The documentation for MoveFileEx makes this clear:

When moving a file, the destination can be on a different file system or volume. If the destination is on another drive, you must set the MOVEFILE_COPY_ALLOWED flag in dwFlags.

So if the source drive is not the same as the destination drive, simply or the MOVEFILE_COPY_ALLOWED flag into dwFlags.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • 2
    I have the same problem. I tried the solution suggested by you and I got ERROR_ACCESS_DENIED 5 (0x5). Any suggestions? I get the error if the file already exists, however I'm interested in performing a proper move operation. – user1232138 Dec 14 '14 at 18:15