Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 遍历所有目录/子目录并获取文件和文件夹的权限_Perl_Directory - Fatal编程技术网

Perl 遍历所有目录/子目录并获取文件和文件夹的权限

Perl 遍历所有目录/子目录并获取文件和文件夹的权限,perl,directory,Perl,Directory,下面是遍历所有目录/子目录并获取文件和文件夹权限的代码段 要求提供文件、文件夹,并检查其他人是否具有w权限。 我已经成功地编写了部分代码,我被一个错误所震惊,我没有看到任何未初始化的值 以下是错误: Use of uninitialized value $retMode in bitwise and (&) at myTest.pl line 24. 代码段: use warnings; use strict; use Data::Dum

下面是遍历所有目录/子目录并获取文件和文件夹权限的代码段 要求提供文件、文件夹,并检查其他人是否具有w权限。 我已经成功地编写了部分代码,我被一个错误所震惊,我没有看到任何未初始化的值

以下是错误:

Use of uninitialized value $retMode in bitwise and (&) at myTest.pl line 24.
代码段:

        use warnings;
        use strict;
        use Data::Dumper;
        use File::stat;
        
        my @dirs = ("/home/mytest");
        my %seen;
        while (my $pwd = shift @dirs) {
                opendir(DIR,"$pwd") or die "Cannot open $pwd\n";
                my @files = readdir(DIR);
                closedir(DIR);
                foreach my $file (@files) {
                        next if $file =~ /^\.\.?$/;
                        my $path = "$pwd/$file";
                        if (-d $path) {
                                next if $seen{$path};
                                $seen{$path} = 1;
                                print "$path \n";
                                push @dirs, $path;
                        }
                        my $info    = stat($path);
                        my $retMode = $info->mode if (defined $info);
                        $retMode = $retMode & 0777;
                        print "$path : $retMode \n";
                        if ($retMode & 002) {
                            # Code comes here if World has write permission on the file
                        }     
                        if ($retMode & 020) {
                            # Code comes here if Group has write permission on the file
                        }

                        #print Dumper \@dirs;
                        # Check for the directory permissions after files
                }
        }
~

输出:

        /home/mytest/.vimBU
        /home/mytest/.vimBU : 488
        /home/mytest/.git
        /home/mytest/.git : 488
        /home/mytest/.profile : 416
        Use of uninitialized value $retMode in bitwise and (&) at myTest.pl line 24.
        /home/mytest/.vim : 0
        /home/mytest/.sh_history : 384
        /home/mytest/.bash_history : 384
这是正确的方法吗?我正在尝试获得文件夹权限之后的文件权限


某些目录您没有权限或与运行时进程相关。它在readdir()之后发生更改; 在第24行之前再添加一行,您将看到

print "No Permission $path\n" and next if not defined $retMode ;

添加
或骰子$
my$info=stat($path)
之后,告诉我们它输出了什么。我将使用
File::Find
代替。does File:Find不抛出权限