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

hi. i am new to perl and i have task that needs to get done for work. i need to copy the contents of a folder in one directory, and paste it in a new directory named by a 5 digit number that was the folder name of the directory. for example: i want to copy c:/folder/folder/12345/contents to c:/newly_created_byscript_that_is_a_5-digit#/contents how would i do this? thanks
  • Comment on copying some directories and placing them in a new directory

Replies are listed 'Best First'.
Re: copying some directories and placing them in a new directory
by polettix (Vicar) on Jul 22, 2005 at 00:04 UTC
    I think that a combination of File::Find, File::Copy (or probably File::Copy::Recursive, which seems to suit your copying needs but needs to be installed) and perlre/perlretut will help you get through your assignment.

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
Re: copying some directories and placing them in a new directory
by Codon (Friar) on Jul 22, 2005 at 00:01 UTC

    You will probably want to start by opening your source dir, then for each of the listings (excpet . and ..) determine if it is a directory or a file. If it is a file, copy it to the destination dir. If it's a directory, make a corresponding directory in your destination dir, open the source subdir and repeat the above steps. Sound recursive? There's a hint.

    Sorry I cannot be more explicit. I've got to catch a vanpool. I'll try to check back in later and see if there are any other answers. If not, I'll bang together a few rocks and get a subroutine that'll get you started.

    Ivan Heffner
    Sr. Software Engineer, DAS Lead
    WhitePages.com, Inc.