in reply to Re: Recursive Directory Copying to Single Target Directory
in thread Recursive Directory Copying to Single Target Directory

The problem is that my program does not work. I took you advice and cleaned it as shown below:
#!/usr/local/bin/perl -w use strict; use File::Find; use File::Copy; my $sourcedirectory = $ARGV[0]; my $targetdirectory = $ARGV[1]; copyfiles(); sub copyfiles() { #the $sourcedirectory below tells the find where to start #looking for files. The .TXT tells it only to return the files #with the path if the file is a .TXT file. It then uses the copy #of File::Copy to copy the entire path\filename to a SINGLE #directory target. find(sub { copy(({win_path{$File::Find::name$/"if(/\.TXT$/)}", "$sourcedirectory"),"$targetdirectory"); } ) } # ruzam figured out the following line on # how to convert the resulting string to MS-DOS complaint format sub win_path { (my $path = shift) =~ s![\\/]+!\\!g; return $path; }

But I get the following error during when I try to run it:

Scalar found where operator expected at notworking.pl line 21, near "$ +File::Find ::name$/" (Missing operator before $/?) String found where operator expected at notworking.pl line 21, near "$ +/"if(/\.TX T$/)}"" (Missing operator before "if(/\.TXT$/)}"?) syntax error at notworking.pl line 21, near "$File::Find::name$/" syntax error at notworking.pl line 23, near ") " Illegal declaration of subroutine main::win_path at notworking.pl line + 27.

Replies are listed 'Best First'.
Re^3: Recursive Directory Copying to Single Target Directory
by ysth (Canon) on Jan 28, 2009 at 07:31 UTC
    That stuff in there is still nothing that makes any sense. You're going to need to decide what has to happen and write the code to do it, not just throw in stuff until it stops complaining.

    A few hints: the directory to look in should be passed to find(), not copy(). copy() should be passed a filename (presumably returned from win_path) and the target directory. You'll need an if statement around the copy() call to make it only called for .TXT files.