Tuesday, September 14, 2010

Using file copy and move in perl

copy function is used for copying a file from one location to another. Its present in File::copy module.
 
use File::Copy; 
copy("C:\temp\file1", "C:\tmp\file1.orig") or die "copy failed: $!";  # will make a copy of file1
copy("C:\temp\Fileout.txt", *STDOUT) or die "copy failed: $!";  # will print Fileout.txt into STDOUT
move("C:\temp\Fileout.txt", "C:\temp2\Fileout.txt") or die "move failed: $!";    # will move first argument to 2nd argument

This doesnt support features like creating backups of file, recursive copying etc. these functions also support file handles as argument.

No comments:

Post a Comment