Skip to content

Instantly share code, notes, and snippets.

@sharow
Created February 21, 2016 12:45
Show Gist options
  • Save sharow/98f468a067de655f80e7 to your computer and use it in GitHub Desktop.
Save sharow/98f468a067de655f80e7 to your computer and use it in GitHub Desktop.
windows::FILE_ATTRIBUTE_ARCHIVE scanner
#!/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