#!/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; } #### c:\20090127\A\01.TXT c:\20090127\A\02.TXT c:\20090127\B\03.TXT c:\20090127\B\04.TXT c:\20090127\B\05.TXT c:\20090127\C\06.TXT #### C:\>perl program.pl c:\20090127\ C:\targetdirectory\ #### c:\targetdirectory\01.TXT c:\targetdirectory\02.TXT c:\targetdirectory\03.TXT c:\targetdirectory\04.TXT c:\targetdirectory\05.TXT c:\targetdirectory\06.TXT