You are not the first one who is facing a problem. That's why I always share the solution of problems on my blog those I have faced. I believe someone will find these helpful.

Tuesday, April 1, 2008

Perl: How to move/rename file

If you want to move file from one directory/folder to another directory/folder, you can use the rename function of Perl. This function takes OldFileName and NewFileName as parameter, then move the file into NewFileName.rename($OldFileName,$NewFileName);

If You want to rename the file "deadman.txt" into new name "aliveman.txt", then below line will rename the file.rename("deadman.txt","aliveman.txt");

If you want to move the file into another directory/folder, then code will berename("deadman.txt","c:\\deadman.txt"); # windowsrename("deadman.txt","/root/deadman.txt"); # linux

Although you can use the mv command from Linux by using system() function. Lots of choice and ways to do in Perl.