Checks the permissions of a file : stat « File « Perl






Checks the permissions of a file

      

    #!/usr/local/bin/perl -w

    use Getopt::Long;

    my $ret = GetOptions ("f|filename:s");
    my $filename = $opt_f || die "Usage: $0 -f filename\n";

    # Check if the file exists
    if (! -e $filename)
    {
       print "The file $filename does not exist.\n";
       exit;
    }

    # Perform a stat on the file.
    my $perms = (stat ($filename))[2] & 07777;
    printf "The octal permissions of the file $filename are %o\n", $perms;

   
    
    
    
    
    
  








Related examples in the same category

1.Getting Information on a File
2.Get return value from stat function
3.Get the file size
4.Get the length of a file
5.File statistics returned from the stat command
6.File stats
7.Call stat function from file handle
8.Lists files in directory; then gets info on files with stat
9.The stat Function for Windows NT File Attributes