Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Additional windows attributes #22
But unless I'm mistaken the hidden attribute is contained in the dwFileAttributes member of our WIN32_FIND_DATA struct, which is already returned/used in the C extension. It's simply discarded here:
Or am I missing something else? Thanks for your quick response.
Yes, you're dead right. However, the API for scandir is pretty much decided now -- it yields lightweight
You've made me think, though -- I wonder if the Windows file attribute info could be stored in one of the non-standard
That would be helpful, but I can see people aren't likely to be clamoring for it.
I know you'd like for scandir to be included in the stdlib (a fine notion), so is that question about windows-specific stat attributes (or using st_flags) a python-dev/ideas question?
(I have an app that indexes across a NFS. Using scandir made a massive improvement in initial indexing time. So, I hate to add back in an extra syscall per file to add checking for hidden files.)
I've just asked about this (adding an st_winattrs attribute to stat result on Windows) on python-dev, and it looks like there's general support. It'd be great to get this into Python 3.5 too (along with scandir if possible :-). Here's the thread and my suggestion for the final "API" for it:
Basically we'd add a ".st_winattrs" attribute with the Win32 file attributes DWORD to the stat result object on Windows. And then we'd add the relevant Windows constants as FILE_ATTRIBUTE_* to the stat module (via _stat.c in CPython). So testing for a hidden file would become:
import os import stat def is_hidden(path): st = os.stat(path) return getattr(st, 'st_winattrs', 0) & stat.FILE_ATTRIBUTE_HIDDEN != 0
As the next step I've opened Issue 21719 on bugs.python.org. Feel free to provide a patch there if you're in a position to (I have to figure out how to compile CPython 3 on Windows), otherwise I hope to get to it in the next couple of weeks.
I'll keep this issue open so we remember to also add it to scandir.