in reply to Re: How to determine a file's type via stat()
in thread How to determine a file's type via stat()

Thanks, but that is not exactly what I was looking for. I know I can use the file-test operators. What I would like to know if if the first bit of the octal returned by stat for mode will reveal what it really is. So, for instance, if the first bit is a 2 then that means "X".

I was trying to avoid using the file-test operators if at all possible. If it is not possible then I will proceed with such.

Any further thoughts?

  • Comment on Re: Re: How to determine a file's type via stat()

Replies are listed 'Best First'.
Re: Re: Re: How to determine a file's type via stat()
by robartes (Priest) on May 09, 2003 at 17:29 UTC
    I know I can use the file-test operators. What I would like to know if if the first bit of the octal returned by stat for mode will reveal what it really is. So, for instance, if the first bit is a 2 then that means "X".

    Actually, that's what the S_IF* functions do for you. If you want to do this yourself, have a look at the bitshift operators (<< and >>) to do bitwise arithmetic.

    CU
    Robartes-

Re: Re: Re: How to determine a file's type via stat()
by Limbic~Region (Chancellor) on May 09, 2003 at 17:30 UTC
    draconis,
    robartes has pointed you in the right direction. Read the docs on stat.

    You can import symbolic mode constants (S_IF*) and functions (S_IS*) from the Fcntl module:
    S_IFREG S_IFDIR S_IFLNK S_IFBLK S_ISCHR S_IFIFO S_IFSOCK S_IFWHT S_ENFMT

    Figure the bitwise math out and create a hash lookup.

    Cheers - L~R