Programming in C: Unit V: File processing

Renaming the File

Syntax with Example C Program

The function rename (), as the name suggests, is used to rename a file. The prototype of the function is : int rename (const char *oldname, const char *newname).Here, oldname specifies the pathname of the file to be renamed and newname gives the new pathname of the file.

RENAMING THE FILE

The function rename (), as the name suggests, is used to rename a file. The prototype of the function is

int rename (const char *oldname, const char *newname)

Here, oldname specifies the pathname of the file to be renamed and newname gives the new pathname of the file. On success, rename () returns zero. In case of error, it will return a non-zero value and will set the errno to indicate the error. When an error occurs neither the file named by oldname nor the file named by newname shall be changed or created.

Points to remember about rename ()

• If the oldname specifies pathname of a file that is not a directory, the newname shall also not point to the pathname of a directory.

• If the oldname specifies the pathname of a directory then the newname shall not point to the pathname of a file that is not a directory. In this case, if the directory named by the newname already exists then it shall be removed and oldname will be renamed to newname.

Look at the program code given below which illustrates the use of rename ().

#include <stdio.h>

main()

{

int success=0;

success = rename ("comments.txt","feedback.txt");

if (success != 0)

printf("\n The file could not be renamed");

return 0;

}

Programming in C: Unit V: File processing : Tag: : Syntax with Example C Program - Renaming the File


Programming in C: Unit V: File processing



Under Subject


Programming in C

CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation



Related Subjects


Professional English II

HS3251 2nd Semester 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation


Statistics and Numerical Methods

MA3251 2nd Semester 2021 Regulation M2 Engineering Mathematics 2 | 2nd Semester Common to all Dept 2021 Regulation


Engineering Graphics

GE3251 eg 2nd semester | 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation


Physics for Electrical Engineering

PH3202 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Basic Civil and Mechanical Engineering

BE3255 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Electric Circuit Analysis

EE3251 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Physics for Electronics Engineering

PH3254 - Physics II - 2nd Semester - ECE Department - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Electrical and Instrumentation Engineering

BE3254 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Circuit Analysis

EC3251 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Materials Science

PH3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation


Basic Electrical and Electronics Engineering

BE3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation


Physics for Civil Engineering

PH3201 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation


Basic Electrical, Electronics and Instrumentation Engineering

BE3252 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation


Physics for Information Science

PH3256 2nd Semester CSE Dept | 2021 Regulation | 2nd Semester CSE Dept 2021 Regulation


Basic Electrical and Electronics Engineering

BE3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation


Programming in C

CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation