Re: Unable to rename the file
- From: "Dilip Naik" <DilipCNaik@xxxxxxxxxxx>
- Date: Tue, 8 Jul 2008 18:14:57 -0700
Are the source and destination on a local volume or a network volume?
Are they in the root of the volume or in some directory?
"chikara" <chikara@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:1D85312A-259C-4237-89DB-D93CFF33E2DD@xxxxxxxxxxxxxxxx
I am using Windows Vista and sometimes fail to rename the file by using
MoveFileEx() when renaming the file after writing data in the file with
WriteFile() and FlushFileBuffers() repeatedly.
The error code "5(ERROR_ACCESS_DENIED)" is returned from GetLastError().
Why does the error occur when renaming the file? Also, what should I do to
prevent from error occurring?
The Following is a sample program to reproduce this problem.
Any help would be appreciated. Thank you.
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
int test() {
unsigned char buf[] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99
};
HANDLE h;
DWORD nbytes;
LPCTSTR fn_tmp = "aaa";
LPCTSTR fn = "bbb";
h = CreateFile(fn_tmp, GENERIC_WRITE, FILE_SHARE_READ |
FILE_SHARE_WRITE, 0, OPEN_ALWAYS, 0, 0);
if (h == INVALID_HANDLE_VALUE) return 0;
if (!WriteFile(h, buf, sizeof buf, &nbytes, 0)) goto error;
if (!FlushFileBuffers(h)) goto error;
if (!CloseHandle(h)) goto error;
if (!MoveFileEx(fn_tmp, fn, MOVEFILE_REPLACE_EXISTING |
MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH)) {
printf("error=%d\n", GetLastError());
return 0;
}
return 1;
error:
CloseHandle(h);
return 0;
}
int main(int argc, char** argv) {
unsigned int i;
for (i = 0;; ++i) {
printf("*%u\n", i);
if (!test()) return 1;
}
return 0;
}
.
- Follow-Ups:
- Re: Unable to rename the file
- From: chikara
- Re: Unable to rename the file
- References:
- Unable to rename the file
- From: chikara
- Unable to rename the file
- Prev by Date: Re: Can I mount a partition read only?
- Next by Date: Re: Unable to rename the file
- Previous by thread: Unable to rename the file
- Next by thread: Re: Unable to rename the file
- Index(es):
Relevant Pages
|
Loading