Re: Unable to rename the file
- From: Sainath , SMB KID <SainathSMBKID@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Jul 2008 01:34:01 -0700
Hi chikara,
Sure ! , i will run the program , can you please provide me the exe , as i
am out of town i dont have visual studio handy.
send it to my email id sainathss@xxxxxxxx
Sainath
SMB KID.
"chikara" wrote:
Thank you for your reply..
I sometime can rename a file, but sometime cannot. The test program repeats
writing data to a file and renaming the file and renaming usually succeeds it
fails randomly though. When I tested with the test program, renaming failed
in a several tens of seconds while it worked with a different trial.
Could you run the program and see if you also see the failure? Thank you.
"Sainath , SMB KID" wrote:
Hi Chikara,
i would perform these test before i automate the process
a) Please check if you are able to rename a file
b) if you are able to successfully rename the file , then please add the
required rights using API , i would suggest to provide full rights and test.
Sainath SMB KID
"chikara" wrote:
The source and destination files are on a local volume.
I executed this sample program on the desktop; therefore these files are
also created on there.
"Dilip Naik" wrote:
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;
}
- References:
- Unable to rename the file
- From: chikara
- Re: Unable to rename the file
- From: Dilip Naik
- Re: Unable to rename the file
- From: chikara
- Re: Unable to rename the file
- From: Sainath , SMB KID
- Re: Unable to rename the file
- From: chikara
- Unable to rename the file
- Prev by Date: Re: I cannot boot Windows XP in safe mode
- Next by Date: Re: Very strange file ??
- Previous by thread: Re: Unable to rename the file
- Next by thread: Re: Can I mount a partition read only?
- Index(es):
Relevant Pages
|
Loading