Perl's stat() emulation for Windows returns at least three different values, see Re^3: Inline.pm and untainting.

You DO NOT NEED the POSIX macro emulations and those ugly decimal notation of file modes if you just want to test if a name belongs to a directory or a plain file, use perls -X functions, especially -d to test for a directory and -f to test for a plain file.

print "$somename is a real directory" if -d($somename); print "$somename is a real plain file" if -f($somename);

Note that those function usually test the link target of a symlink, except of course for -l. If you want "real" files or directories and not symlinks, either test explicitly for a symlink or use lstat(). Think twice before insisting on "real" files or directories. Most people expect symlinks to be completely transparent for applications, so don't violate that expectation except for a very good reason (like running with root privileges in a public writeable directory like /tmp).

# way 1: explicit test print "$somename is a real directory" if !-l($somename) && -d _; print "$somename is a real plain file" if !-l($somename) && -f _; # way 2: using lstat() lstat($somename); print "$somename is a real directory" if -d _; lstat($somename); print "$somename is a real plain file" if -f _;

Note that using a single underscore as argument reuses the struct stat of the last lstat()/stat()/-X, saving slow system calls.

Update:

For the stat() return values on Windows, and the reason why stat() is emulated that way unter Windows, see Re^3: Inline.pm and untainting.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re: POSIX::S_ISDIR() with $stat->mode values from Windows vs. Linux by afoken
in thread POSIX::S_ISDIR() with $stat->mode values from Windows vs. Linux by isync

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.