raymac has asked for the wisdom of the Perl Monks concerning the following question:

I would like to be able to backup a users configuration directories when they experience problems due to corruption within these folders. How can I emulate XCOPY under DOS. I know I can use "system "XCOPY /s /e"" but what is the Perl equivalent. Any help would be appreciated.
  • Comment on How do I emulate DOS XCOPY command under Perl for Windows

Replies are listed 'Best First'.
Re: How do I emulate DOS XCOPY command under Perl for Windows
by thealienz1 (Pilgrim) on Mar 08, 2001 at 23:44 UTC

    Lately I find myself using File::Find more and more often...

    Here this schould help you...

    #Used to recurse through directories and files use File::Find; #Used to copy directory strucutre of "USERS" use File::Path; #Used to copy each file to its directory use File::Copy; #No trailing slash on any of the following #Specify directory to copy $old_dir = '/site/users'; #Specify directory to backup to $new_dir = '/backup/users'; print "Copy Directory structure of $old_dir - "; mkpath([$old_dir, $new_dir], 1, 0777) || die "\n\tCouldn't copy $old_d +ir '$!'"; print "Successful\n"; print "Copying files to new directory -\n"; find(\&each_file,"$old_dir/") || die "\n\tCouldn't copy files '$!'"; print "Succssful\n"; sub each_file{ my $FilePath = $File::Find::name; #Specified comlete location to fi +le #Location to move to my $MovePath = $FilePath; $MovePath=~s/\Q$old_dir\E/\Q$new_dir\E/i; #Do this so it doesn't in +terpret "dir" vairables as regexp print "Copying file $_ - "; copy($FilePath,$MovePath); print "Successful\n"; }

    "The pajamas do not like to eat large carnivore toasters."
    In German: "Die Pyjamas mögen nicht große Tiertoaster essen.
    In Spanish: "Los pijamas no tienen gusto de comer las tostadoras grandes del carnívoro."

Re: How do I emulate DOS XCOPY command under Perl for Windows
by davorg (Chancellor) on Mar 08, 2001 at 21:20 UTC

    There isn't an equivalent command, but you can easily write one using File::Find.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

Re: How do I emulate DOS XCOPY command under Perl for Windows
by jplindstrom (Monsignor) on Mar 09, 2001 at 08:31 UTC
    If all you need is a deep copy of a directory structure, take a look at File::NCopy.

    I wanted just that once, thought about coding my own solution, but then figured that such a thing just MUST be common enough to already exist. And a CPAN search (or three actually) later...

    /J