Created
February 21, 2016 12:45
-
-
Save sharow/98f468a067de655f80e7 to your computer and use it in GitHub Desktop.
windows::FILE_ATTRIBUTE_ARCHIVE scanner
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
#!/usr/bin/env python | |
# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*- | |
import sys | |
import ctypes | |
from pathlib import Path | |
from contextlib import suppress | |
# https://msdn.microsoft.com/ja-jp/library/windows/desktop/gg258117%28v=vs.85%29.aspx | |
def is_archival(path): | |
return bool(ctypes.windll.kernel32.GetFileAttributesW(str(path)) & 0x20) | |
def walk(path): | |
if path.is_file(): | |
return is_archival(path) | |
elif path.is_dir(): | |
return any(walk(p) for p in path.glob('*')) | |
if __name__ == '__main__': | |
path = Path(sys.argv[1]).resolve() | |
for p in path.glob('*'): | |
with suppress(PermissionError): | |
if walk(p): | |
print('{} is archival'.format(p)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment