Search code examples
phpwindowsscandirhidden-files

Does php scandir() exclude hidden files under Windows?


On a Windows system, a backup agent created temporary hidden files of nearly the same name as the original files, and in the same path. This was probably disturbing a process that used PHP scandir().

Now I was wondering if files on Windows having the hidden flag set are excluded by PHP scandir().

There are some articles about the hidden files in Linux style, how scandir() should ignore files that start with a dot, but there is rarely no info about Windows files.


Solution

  • A short test shows that neither scandir() nor glob() or others take care of the hidden flag.

    Here is the experiment and the result:

    enter image description here

    Parts:

    • Windows 7
    • PHP 5.6.9 (x86)
    • Visual Studio 2012 Redistributable x86

    So scandir() does not hide files having the hidden flag set.

    Next question is, can more powerful PHP commands like glob() be configured.

    Firstly, there is no parameter to deal with flags:

    http://php.net/manual/de/function.glob.php

    Secondly, there is this telling comment of Gabriel S. Luraschi:

    http://php.net/manual/de/function.glob.php#110510

    He recommends exec('dir ... \A ...'). But on commercial hostings (if they run on Windows), this will not be allowed.

    To be sure: use the Linux style and ignore files that start with a dot, like here:

    Exclude hidden files from scandir