Perl File::Copy and Apple’s ditto command

You can use Perl’s File::Copy module to move files around your system. The only drawback is that if the files are macbinary and have a resource fork, that portion of the file gets lost. You can use Apples ditto command with –rsrc parameter to move files and maintain the resource.

Following is a perl subroutine I wrote to move files and keep the resource. The script uses both the File::Copy move command and ditto.

sub movefiles{
foreach my $movefile (@filelistarray ) {
system(qq|ditto –rsrc $sourcepath$movefile $destpath$movefile|);
print (LOGFILE “$movefile”.” has gone to the approved folder: “.”$destpath”.”$movefile”.”\n”);
move( “$sourcepath”.”$movefile”, “$backuppath”.”$movefile”) or print (LOGFILE “\tERROR: Cannot move file ” . “$!”);
}

2 Responses to “Perl File::Copy and Apple’s ditto command”

  1. George Says:

    What are the parameters for your function?

  2. bradrice Says:

    A list of file names in a directory are contained in @filelistarray. I do a readdir() into @filelistarray.