use strict; use Cwd; use Getopt::Long; my ($help) = 0; my ($num) = 20; # Number of default loops to run my ($testdir) = ""; my ($verbose) = 0; GetOptions('help|?' => \$help, "num=i" => \$num, "testdir=s" => \$testdir, 'verbose' => \$verbose); # Header print "Beginning Directory Manipulation Testing...\n" if $verbose; $| = 1; # Get the current working directory my $home_dir = getcwd; # Change to the test directory chdir($testdir); # Set up test dirs if they do not exist if (!-d "test") { mkdir("test"); } if (!-d "test1") { mkdir("test1"); } # Change to the test area chdir("test"); # Directory Manipulation for (my $dir = 0; $dir < $num; $dir++) { # Make the directory if (!-d "directory$dir" ) { mkdir("directory$dir", 0755) or die "Can't make $testdir\\test\\directory$dir: $!\n"; } # Change permissions of the directory if ($^O =~ /Win32/) { print "\nRunning chmod from - $home_dir\\..\\..\\bin\\chmod on $testdir\\test\\directory$dir.\n" if ($verbose); if ($verbose) { system($home_dir . "\\..\\..\\bin\\chmod -v a+rwx $testdir\\test\\directory$dir"); } else { system($home_dir . "\\..\\..\\bin\\chmod a+rwx $testdir\\test\\directory$dir"); } } else { system("/bin/chmod 777 directory$dir") or die "Could not chmod directory$dir: $!\n"; } # Copy the directory if ($^O =~ /Win32/) { print "\nRunning $home_dir\\..\\..\\bin\\cp on $testdir\\test\\directory$dir.\n" if ($verbose); system("$home_dir\\..\\..\\bin\\cp -rv directory$dir copieddirectory$dir"); } else { system("/bin/cp -r directory$dir copieddirectory$dir") or die "Could not copy directory$dir to copieddirectory$dir: $!\n"; } # Rename the directory if (!-d "copieddirectory$dir") { print "copieddirectory$dir does not exist!\n" if $verbose; } if ($^O =~ /Win32/) { system("move copieddirectory$dir ..\\test1\\moveddirectory$dir > out.txt"); if (-e "out.txt") { unlink("out.txt"); } } else { system("/bin/mv copieddirectory$dir ../test1/moveddirectory$dir") or die "Could not move directory$dir: $!\n"; } # Delete the copied directory if ($^O =~ /Win32/) { rmdir("..\\test1\\moveddirectory$dir"); } else { system("/bin/rm -r ../test1/moveddirectory$dir") or die "Could not remove moved directory$dir: $!\n"; } # Remove the directory if ($^O =~ /Win32/) { rmdir("directory$dir") or die "Can't remove directory: $!\n"; } else { system("/bin/rm -r directory$dir") or die "Could not remove directory$dir: $!\n";; } }