Perl rename Function

Advertisements


Description

This function renames the file with OLDNAME to NEWNAME. Uses the system function rename( ), and so it will not rename files across file systems or volumes. If you want to copy or move a file, use the copy or move command supplied in the File::Copy module.

Syntax

Following is the simple syntax for this function:

rename OLDNAME, NEWNAME

Return Value

This function returns 0 on failure and 1 on success.

Example

First create test file in /tmp directory and then use following code to change file name.

#!/usr/bin/perl -w

rename("/tmp/test", "/tmp/test2") || die ( "Error in renaming" );

When above code is executed, it produced following result.

the file gets renamed


Advertisements
Advertisements