Hello all,
A program of mine uses
CreateFile,offset [@@FLE_Temp],GENERIC_WRITE or GENERIC_READ, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY or FILE_FLAG_DELETE_ON_CLOSE, 0
to open a temporary, auto-deleting file.
But sometimes have the need to save the contents of that temporary file.
I've tried MoveFile as well as CopyFile, but both complain about the source file being open (it is, no debate about that). As far as I know that FILE_SHARE_READ flag should have been enough, but it looks like I'm missing something ...
Anyone have an idea what I'm missing ?
Remark: Windows XP sp3
You may have noticed that Windows often gets fanatically
possessive of files.
The KISS principle goes a long way toward dealing with this.
As a general rule, I never use an OS-specific API when there's
something in the C run-time library that does the job.
As a general rule, I never use an OS-specific API when there's
something in the C run-time library that does the job. That way
my programs remain portable to other OSes.
Hello all,
A program of mine uses
CreateFile,offset [@@FLE_Temp],GENERIC_WRITE or GENERIC_READ, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY or FILE_FLAG_DELETE_ON_CLOSE, 0
to open a temporary, auto-deleting file.
But sometimes have the need to save the contents of that temporary file.
I've tried MoveFile as well as CopyFile, but both complain about the source file being open (it is, no debate about that). As far as I know that FILE_SHARE_READ flag should have been enough, but it looks like I'm missing something ...
Anyone have an idea what I'm missing ?
Remark: Windows XP sp3
Regards,
Rudy Wieser
I've tried MoveFile as well as CopyFile, but both complain about the
source file being open (it is, no debate about that). As far as I know
that FILE_SHARE_READ flag should have been enough, but it looks like
I'm missing something ...
Anyone have an idea what I'm missing ?
Use the FILE_SHARE_DELETE sharing flag.
But it would be pointless if you use FILE_FLAG_DELETE_ON_CLOSE.
Don't use that flag. Delete manually.
I forgot to mention that, if the file is moved, if it's moved to a
different drive, any data writtin into the file after the file was
moved, will not be applied to the moved file. e.g.:
If the file was moved to the same drive, the moved file will have
the written data.
I think that's the limitation of the FILE_SHARE_DELETE flag. Since
it controls whether the directory entry for the file can be modified
or not.
Moving the file to a different drive would be a copy of the directory
entry, instead of modifying the existing one.
When I try a copy I got the "in use" error every time, no matter
what attributes I created the temp file with.
That would require FILE_SHARE_READ, and without FILE_FLAG_DELETE_ON_CLOSE.
FILE_FLAG_DELETE_ON_CLOSE description says:
"Subsequent open requests for the file fail, unless the FILE_SHARE_DELETE share mode is specified."
Use the FILE_SHARE_DELETE sharing flag.
I tried that with both the copy as well as the move.
The move does actually works, but the moved file (ofcourse?) disappears when the file-handle gets closed.
When I try a copy I got the "in use" error every time, no matter what attributes I created the temp file with.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 41:51:22 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,857,792 |