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

Hello ,
I'm trying to write a program that would read a delimited file take a file path out the file, search for a word document in the directory and copy it to another directory.
So far, I'm able to parse the file pass the path as a variable and search but it only finds one file. I'm on a Windows environment, so I don't know if commands in UNIX would work as well; I'm sort of limited. I would like to know if you have any suggestions: Here is the code:
opendir MYDIR, 'H:/' or die $! ; my @allfiles = grep { $_ ne '.' and $_ ne '..' } readdir MYDIR ; my @files = grep { !-d } @allfiles ; my @dirs = grep { -d } @allfiles ; print "Current directory contains " . @files . " files and " . @dirs . " directories.\n" ;

update (broquaint): added formatting

Replies are listed 'Best First'.
Re: Find files and copying to another directory
by Joost (Canon) on Feb 14, 2003 at 17:14 UTC
    Take a look at File::Copy, File::Path. and maybe File::Find.

    These are all standard modules, and will work on all platforms.

    -- Joost downtime n. The period during which a system is error-free and immune from user input.
Re: Find files and copying to another directory
by Hagbone (Monk) on Feb 14, 2003 at 18:04 UTC
    Sounds like you're pulling a file name from your delimited file, and using it to find (somewhere) any files that match, and when a match is found, copy that file to another directory/location.

    Assuming that's correct, I agree with Joost, that File::Find and File::Copy are the way to go, 'cause you need to traverse recursively. Something like (untested):

    find(\&findit,'/path/to/highest/level/dir/you/need/to/start/from'); sub findit { /^your_regex$/ && ## your match regex would replace "your_regex" copy("$File::Find::name","/path/to/copy/location/$_") }
    Probably flaws in my suggestion, but hopefully this will get you headed in the right direction.