Re: Unable to rename the file



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;
}



.



Relevant Pages

  • Re: Unable to rename the file
    ... We can also rename a file using MoveFile() and Move FileEX, ... writing data to a file and renaming the file and renaming usually succeeds it ... if ) goto error; ...
    (microsoft.public.windows.file_system)
  • Re: Unable to rename the file
    ... I sometime can rename a file, ... writing data to a file and renaming the file and renaming usually succeeds it ... "Sainath, SMB KID" wrote: ... if ) goto error; ...
    (microsoft.public.windows.file_system)
  • Re: Infinity......
    ... I cannot rename all of A elements by replacing ... the same absolute size, then the absolute size of A ... Yes, there is a way of renaming the elements of B, ... if there is a bijection between sets A and B, ...
    (sci.math)
  • Acritum Sophisticated Rename 3.00
    ... Sophisticated Rename is a powerful Windows utility that simplifies the ... You specify the rules for a renaming task ... Exif editor can conduct various Exif date and time manipulations, ... Exif or ID3 tag into the renaming template. ...
    (comp.software.shareware.announce)
  • Re: =?iso-8859-5?b?3NDZ4eLe4A==?= - =?iso-8859-5?b?5N7i3tPg0OTY4tU=?=
    ... directories, based upon flexible criteria. ... can quickly rename them all to "htm" or other. ... also add incrementing numbers to the file name, add a suffix or prefix, ... different renaming methods and also supports MP3 tags. ...
    (soc.culture.bulgaria)

Loading