How to rename a file in C ?

The capability of renaming a file in C , is provided by the C standard library , rename function , which is part of the stdio header file .

This function takes the path of the file to rename , including the name of this file , and a path ending , with the new file name .

If a file already exists with that name , it is implementation defined , how this function behaves . For example , under Unix , the file with the same to be renamed new file name , is deleted , and the file is renamed to its new name , while under windows the call to this function will fail .

This function can rename files and directories under windows , and unix like operating systems .

Upon success the rename function returns 0 , and upon failure , it will return a non zero value , and the filename is not changed . Also upon failure , the errno error code is set , so information about the kind of encountered problems , can be gotten using perror .



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store