Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Win32 API for rename a file in C

If the source directory and the target directory, MoveFile would actually make a copy of the source file into the target file, which means that I will end up seeing two files.

Is that the best way that rename can be achieved?

like image 293
tom Avatar asked Dec 22 '10 18:12

tom


People also ask

How do you rename a file in C++?

int rename( const char *oldname, const char *newname ); The rename() function takes a two arguments: oldname , newname and returns an integer value. It renames the file represented by the string pointed to by oldname to the string pointed to by newname . It is defined in <cstdio> header file.

How can I quickly rename a file?

You can press and hold the Ctrl key and then click each file to rename. Or you can choose the first file, press and hold the Shift key, and then click the last file to select a group.

What methods will rename a file?

There are many ways to rename a file in Windows. The easiest way is by right-clicking on the file and selecting Rename. You can then type a new name for your file and press enter to finish renaming it. A quicker way to rename a file is by first selecting it by left clicking on it, then pressing the F2 key.


1 Answers

What does your code look like? I have this:

if(MoveFile(_T("c:\\hold\\source"),_T("c:\\hold\\dest")))
{
    printf("succeeded\n");
}else
{
    printf("Error %d\n",GetLastError());
}

and it does not leave the source behind.

like image 70
weloytty Avatar answered Oct 20 '22 22:10

weloytty