#!/usr/local/bin/perl -W # force taint checks, and print warnings #use strict; # install all three strictures use File::Copy; $|++; # force auto flush of output buffer #define full path to source folder $path = "sourceDirectory"; #define path to new folder $newpath = "destinationDirectory"; #recursively search $path for files opendir (ORIG , $path); while ($name = readdir(ORIG)){ print "$name\n" ; @Filenames; push (@Filenames, $name); #print " $newpathandfile\n"; } closedir(ORIG); chdir($path) || die "cannot move to $path"; foreach $X (@Filenames){ my $destFile = $newpath.$X; print '$destFile'." = $destFile\n"; copy( "$X" , "$destFile" ) or print "File cannot be copied. $!\n"; }