Skip to content

Instantly share code, notes, and snippets.

@mattst
Created April 11, 2017 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattst/c464c566c8c45b66792308df13872392 to your computer and use it in GitHub Desktop.
Save mattst/c464c566c8c45b66792308df13872392 to your computer and use it in GitHub Desktop.
# Code to test the reliability of windll.kernel32.GetFileAttributesW()
# by running it on every file (that has read access) on the file system.
import os, os.path, sys
from ctypes import windll
HIDDEN_FILE_ATTRIBUTE = 2
GET_ATTRIBUTES_FAILED = -1
def CheckDirectory(directory):
try:
dir_list = os.listdir(directory)
# User has no read access in directory.
except PermissionError:
dir_list = []
for filename in dir_list:
path = os.path.join(directory, filename)
file_attributes = windll.kernel32.GetFileAttributesW(path)
if file_attributes == GET_ATTRIBUTES_FAILED:
print("GetFileAttributesW() failed: {}".format(path))
user_continue = input("Continue?")
else:
is_hidden = bool(file_attributes & HIDDEN_FILE_ATTRIBUTE)
print("{} - {}".format(path, is_hidden))
if os.path.isdir(path):
CheckDirectory(path)
CheckDirectory("C:\\")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment