Created
April 11, 2017 21:08
-
-
Save mattst/c464c566c8c45b66792308df13872392 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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