in reply to Re: Recursive Directory Copying to Single Target Directory
in thread Recursive Directory Copying to Single Target Directory
#!/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 |