$dir = "c:\\this_empty_dir";
if (-d $dir) { #dir exists
opendir(D,$dir) || die "opendir $dir: $!"; #dir opened successfully
@dir_entries = readdir(D); #read in dir entries to array
if (scalar(@dir_entries) == 2) {
print "empty dir\n"; #entries for "." and ".." found (total == 2)
== empty dir
} else {
print "non-empty ----- number of dir entries:
".scalar(@dir_entries)."\n";
}
} else {
print "Dir does not exist.\n";
}
Steven
-----Original Message-----
From: John Deretich [mailto:[EMAIL PROTECTED]
Sent: Friday, September 26, 2003 3:05 PM
To: Steven Manross
Cc: Perl-Win32-Admin-Request (E-mail)
Subject: RE: removing an empty directory
Do you know how to test
for the existence of an empty directory?
thanks,
John
-----Original Message-----
From: Steven Manross [mailto:[EMAIL PROTECTED]
Sent: Friday, September 26, 2003 3:01 PM
To: John Deretich
Subject: RE: removing an empty directory
Or change the current directory to that directory first..
Steven
-----Original Message-----
From: John Deretich [mailto:[EMAIL PROTECTED]
Sent: Friday, September 26, 2003 2:56 PM
To: Steven Manross
Cc: Perl-Win32-Admin-Request (E-mail)
Subject: RE: removing an empty directory
Thanks,
I found out, that I need to add the full path
to the file $directoryempty = $searchdrive1 . $directoryempty;
regards,
John
-----Original Message-----
From: Steven Manross [mailto:[EMAIL PROTECTED]
Sent: Friday, September 26, 2003 11:17 AM
To: John Deretich; Perl-Win32-Admin-Request (E-mail)
Subject: RE: removing an empty directory
#put this after your rmdir
print Win32::FormatMessage(Win32::GetLastError())."\n";
# or add $! To your warn statement
They will tell you why it thinks it didn't work.. $! Numerically, and
the print statement formatted. You could probably combine the
FormatMessage with $! As well, though I haven't tried.
Steven
-----Original Message-----
From: John Deretich [mailto:[EMAIL PROTECTED]
Sent: Friday, September 26, 2003 10:56 AM
To: Perl-Win32-Admin-Request (E-mail)
Subject: removing an empty directory
Hello,
I was wondering if anyone would know
why rmdir wouldn't remove an empty directory?
This is the code that I'm using:
use strict;
my $directoryempty = undef;
my $searchdrive1 = 'I:\\';
opendir(EMPTYDIR, $searchdrive1) ;
while($directoryempty = readdir(EMPTYDIR) ) {
chomp $directoryempty;
rmdir ("$directoryempty") || warn "Cannot remove directory
$directoryempty\n";
}
thanks,
John
_______________________________________________
Perl-Win32-Admin mailing list [EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs