I want to delete the files from a directory then delete the directory.
I have code which processes a file containing a list of files, one per line.
That routine creates a subdirectory based on the file name and then writes files to the subdirectory.
I have the following code to process the same file containing the list of file names, deleting the files in the relevant subdirectory then attempting delete the directory.
However, when attempting to delete the directory the routine indicates that permission is denied.
The code follows the source, delete_dir.pl is attached. Also is an example of the source for delete_dir.pl
The command line input is delete_dir.pl dir_test.txt
Thanks in advance for your feedback.
use strict;
use warnings;
open(INFILE, "< $ARGV[0]") || die("can't open inputfile: $ARGV[0]");
my $fname = "";
my $fext = "";
my $wait = "";
my $name = "";
my $retval = "";
while (<INFILE>) {
chomp($_);
print "$_\n";
($fname,$fext) = split(/\./,$_);
print "file name: $fname\n";
print "file extension: $fext\n";
opendir(DIR, $fname) || print "no $fname directory!\n";
$wait = <STDIN>;
while ($name = readdir(DIR)) {
print "$name\n";
$name = $fname."\\".$name;
unlink($name);
print "$name\n";
}
rmdir($fname) || warn "cannot delete $fname: $!";
$wait = <STDIN>;
} #endwhile
DTR012008DT040929.PRN DTR112008DT040929.PRN=
delete_dir.pl
Description: Binary data
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>