Re: Permission denied to delete an empty folder
by matija (Priest) on Apr 28, 2004 at 10:56 UTC
|
Note that the permissions for deleting the folder aren't the permissions on the folder, they are the write permissions of the parent!. I got bitten by that, once or twice - usualy when I didn't want to delete that specific folder, but wanted to delete all the other files and folders. | [reply] |
Re: Permission denied to delete an empty folder
by bronto (Priest) on Apr 28, 2004 at 10:46 UTC
|
Check the permissions of the folder, correct them, then rerun your script :-)
Seriously: which ownership runs your script under? which ownership/permissions are set on the folder?
Ciao! --bronto
The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz
| [reply] |
|
|
- Thanks for replying, but how can I do it,
"Check the permissions of the folder, correct them"
- I'm new in perl,excuse me if it's very obvious!
| [reply] |
|
|
Nelly, detail your question. What operating system are you using? Can you show a little snippet of your script?
See also the other replies, e.g.: are you running your script under the same directory you are trying to delete?
Thanks
Ciao! --bronto
The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz
| [reply] |
Re: Permission denied to delete an empty folder
by Corion (Patriarch) on Apr 28, 2004 at 10:55 UTC
|
Additionally to what bronto said, under Win32, an application that is still running and has the directory in question as its current working directory will also prevent the directory from being deleted.
| [reply] |
How can I Check the permissions of the folder,and correct them?
by Nelly (Novice) on Apr 28, 2004 at 11:43 UTC
|
- How can I Check the permissions of the folder,and correct them?
I'm new in perl,excuse me if it's very obvious!
| [reply] |
|
|
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat($filename);
set:chmod
see perlfunc for more details stat chmod.
| [reply] [d/l] [select] |
|
|
Well I don't know your system but on Win32 its tricky. Here is how. Its actually a subroutine to check if a directory is empty and then remove it (of course you could just force it to remove it with the the "rmtree" command, but better to be safe).
Also uncomment the commented-out section if you want it to display the folder permissions mask before you alter them.
What I don't like about this code is that doing a directory listing to check if a directory is empty is slow, especially if a directory is large. There could be an easy command to do that that I'm simply not aware of (probable!).
#!perl
use Win32::FileSecurity;
use Cwd qw(cwd);
use File::Path;
use strict;
use warnings;
sub remove_dir {
my ($path) = @_;
my $currpath = cwd;
my $ok = chdir $path;
if ($ok) {
my @dir = <*>;
## check if directory is empty
if (!@dir) {
my $dirmask = Win32::FileSecurity::MakeMask( qw(FULL GENER
+IC_ALL) );
my %hash;
# if ( Win32::FileSecurity::Get( $path, \%hash ) ) {
# while( (my $name, my $mask) = each %hash ) {
# print "$name:\n\t";
# my @happy;
# Win32::FileSecurity::EnumerateRights( $mask, \@happy
+) ;
# print join( "\n\t", @happy ), "\n";
# }
# }
Win32::FileSecurity::Get( $path, \%hash);
$hash{Administrator} = $dirmask;
$ok = chdir $currpath;
if ( Win32::FileSecurity::Set($path, \%hash) ) {
print "\n\t$path --> Permissions Changed";
} else {
print "\n\t$path --> Permission change failed$!\n$^E";
}
if (rmtree $path) {
print "\n\t$path --> Removed";
} else {
print "\n\t$path --> Can't be removed $!\n$^E";
}
}
}
}
| [reply] [d/l] |
|
|
| [reply] |
|
|
| [reply] |