Search code examples
perlbatch-filexcopy

How would I emulate the xcopy command in Perl?


Perl is a new language to me. I've been writing batch files. I have a script that I wrote as a batch file that I am trying to convert to Perl. This is my batch file:

    @echo off
    :LOOP
    echo File Copy Started 
    xcopy /s /Y  "Source" "Destination"
    echo File Copy Completed 
    TIMEOUT /T 80
    goto :LOOP

So I"m trying figure out if there is a command similar to xcopy in Perl or if I would need to figure out some other way to create the same function in Pearl. Any help would be great. Thanks.


Solution

  • As ikegami notes in the comments, there is no single Perl command to do what xcopy does. While you could write some code to reimplement recursive file copying in Perl (e.g. using File::Find or File::Find::Rule and File::Copy as suggested), a simpler solution may be to just invoke xcopy from Perl using system:

    system qw(xcopy /s /Y), $source, $destination;
    

    Edit: Or just use File::Copy::Recursive from CPAN.