5. Copy and move files

The module File::Copy is default in Perl. It provides two basic functions, copy and move, which are useful for getting the contents of a file from one place to another.

5.1 Copy

To copy e.g. .txt files from the current directory into the existing (!) directory Sub, write

$ perl -MFile::Copy -e '@files= glob("*.txt"); copy("$_", "Sub/$_") for (@files);'
'Copying' means that the text files in the current directory are still there.

5.2 Move

To move e.g. .srt files from the current directory into the existing (!) directory Sub, write

$ perl -MFile::Copy -e '@files= glob("*.srt"); move("$_", "Sub/$_") for (@files);'
'Moving' means that the text files in the current directory are removed.

Remark:
The functions copy and move return 1 on success, 0 on failure. $! will be set if an error was encountered. You could add or die $! to the previous commands.