コード例 #1
0
 def os_listdir(path):
     data = wintypes.WIN32_FIND_DATAW()
     data_p = ctypes.byref(data)
     filename = os.path.join(path, '*')
     handle = scandir.FindFirstFile(filename, data_p)
     if handle == scandir.INVALID_HANDLE_VALUE:
         error = ctypes.GetLastError()
         if error == scandir.ERROR_FILE_NOT_FOUND:
             return []
         raise scandir.win_error(error, path)
     names = []
     try:
         while True:
             name = data.cFileName
             if name not in ('.', '..'):
                 names.append(name)
             success = scandir.FindNextFile(handle, data_p)
             if not success:
                 error = ctypes.GetLastError()
                 if error == scandir.ERROR_NO_MORE_FILES:
                     break
                 raise scandir.win_error(error, path)
     finally:
         if not scandir.FindClose(handle):
             raise scandir.win_error(ctypes.GetLastError(), path)
     return names
コード例 #2
0
ファイル: benchmark.py プロジェクト: dholth/scandir
 def os_listdir(path):
     data = wintypes.WIN32_FIND_DATAW()
     data_p = ctypes.byref(data)
     filename = os.path.join(path, '*')
     handle = scandir.FindFirstFile(filename, data_p)
     if handle == scandir.INVALID_HANDLE_VALUE:
         error = ctypes.GetLastError()
         if error == scandir.ERROR_FILE_NOT_FOUND:
             return []
         raise scandir.win_error(error, path)
     names = []
     try:
         while True:
             name = data.cFileName
             if name not in ('.', '..'):
                 names.append(name)
             success = scandir.FindNextFile(handle, data_p)
             if not success:
                 error = ctypes.GetLastError()
                 if error == scandir.ERROR_NO_MORE_FILES:
                     break
                 raise scandir.win_error(error, path)
     finally:
         if not scandir.FindClose(handle):
             raise scandir.win_error(ctypes.GetLastError(), path)
     return names