codekingpro/portable-devtools
115k
1import platform2 3 4def windows_only(func):5 if platform.system() != 'Windows':6 return lambda *args, **kwargs: None7 return func8 9 10@windows_only11def hide_file(path: str) -> None:12 """13 Set the hidden attribute on a file or directory.14 15 From https://stackoverflow.com/questions/19622133/16 17 `path` must be text.18 """19 import ctypes20 import ctypes.wintypes21 22 SetFileAttributes = ctypes.windll.kernel32.SetFileAttributesW23 SetFileAttributes.argtypes = ctypes.wintypes.LPWSTR, ctypes.wintypes.DWORD24 SetFileAttributes.restype = ctypes.wintypes.BOOL25 26 FILE_ATTRIBUTE_HIDDEN = 0x0227 28 ret = SetFileAttributes(path, FILE_ATTRIBUTE_HIDDEN)29 if not ret:30 raise ctypes.WinError()31 