#!/usr/bin/perl
use File::Copy;
my $indir = $ARGV[0];
my $outdir = $ARGV[1];
if (!-e $indir){print "\n\n$indir does not exist"; exit();}
if (!-e $outdir){print "Don't see $outdir, attempting to create\n"; &deepdir($outdir);}
if (!-d $outdir){print "Copy failed. If a file named $outdir exist copy cannot proceed.\n"; exit();}
&sub_to_copy_dir($indir, $outdir);
sub sub_to_copy_dir
{
my ($indir, $outdir) = @_;
opendir SDIR, $indir;
my @filenames = grep (!/^\.\.?$/ , readdir (SDIR));
closedir SDIR;
foreach $file (@filenames)
{
my $fn = "$indir\\$file";
if (-d $fn)
{
if (!-e "$outdir\\$file")
{
mkdir ("$outdir\\$file", 0777) || die "\n\nUnable to create directory $outdir\\$file\n\n";
}
if (!-d "$outdir\\$file")
{
print "Copy failed. If a file named $outdir\\$file exist copy cannot proceed.\n";
exit();
}
&sub_to_copy_dir($fn, "$outdir\\$file");
}
else
{
print "Processing $fn\n";
copy "$fn", "$outdir\\$file";
}
}
}
sub deepdir
{
my $outdir = shift;
my @A1 = split (/\\/, $outdir);
for ($i=1; $i < @A1; $i++)
{
print "i = $i\n";
$A1[0] = "$A1[0]\\$A1[$i]";
print "Testing for existance of $A1[0]\n";
if (!-e $A1[0])
{
print "Attempting to create $A1[0]\n";
unless (mkdir ("$A1[0]", 0777))
{
if (-e $A1[0])
{
print "\n\n$outdir does not exist.\nUnable to create $outdir.\nCheck for a file with the name $A1[0]";
exit();
}
print "\n\n$outdir does not exist.\nUnable to create $outdir.\nCheck for and error in the name around $A1[0]";
exit();
}
print "$A1[0] successfully created\n";
}
}
}
-----Original Message-----
From: Matthew Thompson [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 11, 2001 10:30 AM
To: 'Lee Goddard'; Kristofer Wolff; perllist
Subject: RE: copy directories
Yeah - I rember a util called xxcopy coming up. It would be worth searching
for xxcopy.
Matt
-----Original Message-----
From: Lee Goddard [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 11, 2001 3:21 PM
To: Kristofer Wolff; perllist
Subject: RE: copy directories
There's loads of stuff on this in the archives.
lee
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
Kristofer Wolff
Sent: 11 April 2001 16:23
To: perllist
Subject: copy direcktorys
i am looking for a way to copy directorys including subdirectorys and
files... any idea ?
if there is a perl-module ???
thanks
Ven
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web
