I am using c++ stdio.h's
int rename ( const char * oldname, const char * newname );
rename() function to rename a folder but occasionally it fails to rename the folder and returns -1.
Is there any way to know why is rename() failing?
any way to know this error explanation via any c++ function.
When a file or folder is still open, Windows doesn't allow users to rename it. Therefore, you must ensure that no files or folders are open and no apps are running in the background while you're renaming. To do that, simply click on the same file again to open it, and it will take you to the already opened tab.
rename() function is used to change the name of the file or directory i.e. from old_name to new_name without changing the content present in the file. This function takes name of the file as its argument.
Find and select the file, then select File > Rename. Type the new name and press Enter.
We feel the F2 keyboard shortcut is the fastest way to rename a bunch of files, whether you are trying to add different names for each of them or change all their names in one go.
It should be possible to get the concrete error from errno.h
#include <errno.h>
#include <string.h>
...
if(rename("old","new") == -1)
{
std::cout << "Error: " << strerror(errno) << std::endl;
}
The errno
error codes for rename
are OS-specific:
_errno
instead of errno
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With