def hiddenCheck(self, directory): dirs = directory.split(os.sep) # If any subpart of the directory structure start with a dot # we exclude it for subdir in dirs: # Exclude dot directories on any OS if subdir.startswith("."): return True # On Windows check the directories attributes # if the win32file module is available if win32: try: from win32file import GetFileAttributes except ImportError as e: pass else: dirattr = GetFileAttributes(directory.replace('\\', '\\\\')) # Set a mask to check the 2nd bit # See https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx # FILE_ATTRIBUTE_HIDDEN # 2 (0x2) mask = 1 << 1 if dirattr & mask: return True return False
def isLinkedDir(targetPath): r"""Detects whether the given path is a NTFS junction. #Later: Fix: This call fails when the target points to an invalid location. """ # #From: http://stackoverflow.com/questions/1447575/symlinks-on-windows result = GetFileAttributes(targetPath) return result > -1 and result & REPARSE_FOLDER == REPARSE_FOLDER
def islink(path): """ Cross-platform islink implementation. Supports Windows NT symbolic links and reparse points. """ if sys.platform != "win32" or sys.getwindowsversion()[0] < 6: return os.path.islink(path) return os.path.exists(path) and _check_bit(GetFileAttributes(path), stat.FILE_ATTRIBUTE_REPARSE_POINT)
def hiddenCheck(self, stuff): subdirs = stuff['dir'].split(os.sep) # If any part of the directory structure start with a dot we exclude it for part in subdirs: if part.startswith("."): return True # If we're asked to check a file we exclude it if it start with a dot if 'file' in stuff and stuff['file'].startswith("."): return True # On Windows check the directories attributes if the win32file module is available if win32: try: from win32file import GetFileAttributes except ImportError as e: # noqa: F841 pass else: if 'file' in stuff: # If it's a file it must contain the fully qualified path path = os.path.join(stuff['dir'], stuff['file']).replace('\\', '\\\\') else: path = stuff['dir'].replace('\\', '\\\\') attrs = GetFileAttributes(str(path)) # Set a mask to check the 2nd bit # See https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx # FILE_ATTRIBUTE_HIDDEN # 2 (0x2) mask = 1 << 1 if attrs & mask: return True return False
def iswinlink(fpath): if sys.platform[:3] == "win": if GetFileAttributes(fpath) & REPARSE_FOLDER == REPARSE_FOLDER: return True return False