in reply to File::Find, chmod and warnings
chmod($dirmode, $_) if (-d $_) or warn $!;
if (-d $_) or warn $!;
would always return true, since warn is always there, and everything, both files and directories were made 0755. My solution is (without Bart's correct fixes about octal() ) :
#!/usr/bin/perl -w use strict; use File::Find; my $topdir = shift || '.'; my $filemode = shift || 0644; my $dirmode = shift || 0755; find(\&doit, "$topdir"); sub doit { return if $_ eq "." or $_ eq ".."; if(-f $_){chmod($filemode, $_)or warn $!} if(-d $_){chmod($dirmode, $_) or warn $!} }
|
|---|