-
November 28th, 2013, 01:31 AM
#1
File Open Failed After CopyFileW
Hi,
I am facing an issue of file open failure after CopyFileW.
I suspect that some of the handle which is part of copy is still holding the file.
How can i wait till the OS handle free the file.
Any API's available to check this ?
-Dave
-
November 28th, 2013, 02:11 AM
#2
Re: File Open Failed After CopyFileW
1. Define "failed".
2. What is the reason of your "suspection"?
3. You may also want to show your code.
Victor Nijegorodov
-
November 28th, 2013, 06:59 AM
#3
Re: File Open Failed After CopyFileW
I am facing an issue of file open failure after CopyFileW.
On the original? On the copy?
As Victor said in his post #2, it would be helpful if you posted the code so we could comment further.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 28th, 2013, 08:07 AM
#4
Re: File Open Failed After CopyFileW
If you copied over the network, then yes, this can happen. The OS will release the copy command early.
It can also happen with a local copy as well if the copy and open are in another process. The copy is complete, but it takes the OS file system a while to finish up all the linkages in the filesystem for the other thread to see it (this can take up to a few seconds), and it can take considerably longer still on slower devices such as memorysticks.
There's not much you can do about it, try to open the file, if it fails, wait/sleep a short while and retry.
-
December 3rd, 2013, 05:19 AM
#5
Re: File Open Failed After CopyFileW
The same issue can arise if you programmatically terminate a process that has open files. It takes a while for the OS to clean up the mess and release the file handles, so a retry loop will be needed.
Nobody cares how it works as long as it works
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|