Skip to content
Related Articles

Related Articles

Perl | rename() Function
  • Last Updated : 25 Jun, 2019
GeeksforGeeks - Summer Carnival Banner

rename() function in Perl renames the old name of a file to a new name as given by the user.

Syntax: rename(old_file_path, new_file_path)

old_file_path: path of the old file along with its name
new_file_path: path of the new file along with its name

0 on failure and 1 on success


#!/usr/bin/perl -w
# Calling the rename() function 
# with required parameters
rename("D:/GeeksforGeeks/GFG File.txt",
       "D:/GeeksforGeeks/GFG File 2.txt") ||
       die ( "Error in renaming" );


Original File:

Running the Command:

Updated File:

Steps to Run the above code:
Step1: Create a file anywhere in your System and copy the File Path.
Step 2: Provide the path of your File in the code above and save it as .pl extension.
Step 3: Run the above code in Command line as perl
Step 4: Name of the File is now changed with the new name provided.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :