Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I have a file that I need to find the permissions and file type for. However, I have a small problem with it. I do not see the permissions or type, just numbers. Here is the code:

$fileMode = (stat $dirItem)[2];

Here is a sample number I get back from a file: 33279

How do I convert the numbers into type and permissions? I am using Windows NT.

Thanks for any help

Replies are listed 'Best First'.
Re: using stat
by jdporter (Paladin) on Feb 10, 2003 at 18:38 UTC
    Using stat to get file permissions info on Windows isn't going to give you very much useful, because permissions are managed in a completely different way than on Unix, which is where stat comes from.
    Instead, check out the Win32::FileSecurity module for methods to get useful info on Windows.

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.

Re: using stat
by LD2 (Curate) on Feb 10, 2003 at 18:37 UTC
    check out this documentation

    here's an example from it:
    Because the mode contains both the file type and its permissions, you +should mask off the file type portion and (s)printf using a "%o" if y +ou want to see the real permissions. $mode = (stat($filename))[2]; printf "Permissions are %04o\n", $mode & 07777;In scalar context, +stat returns a boolean value indicating success or failure, and, if s +uccessful, sets the information associated with the special filehandl +e _. The File::stat module provides a convenient, by-name access mechanism: use File::stat; $sb = stat($filename); printf "File is %s, size is %s, perm %04o, mtime %s\n", $filename, $sb->size, $sb->mode & 07777, scalar localtime $sb->mtime;