Esempio n. 1
0
    def _getSize(self, path):
        """
        This private method calculates the total size
        of a folder or volume, and accepts a UNC or
        local path.
        """

        if self.verbose: print(path)

        # Get the list of files and folders.
        try:
            items = _win32file.FindFilesW(path + "\\*")
        except _win32file.error as details:
            self.errors[path] = str(details[-1])
            return

        # Add the size or perform recursion on folders.
        for item in items:

            attr = item[0]
            name = item[-2]
            size = item[5]

            if attr & 16:
                if name != "." and name != "..":
                    self._getSize("%s\\%s" % (path, name))

            self.totalSize += size

            if self._stopSize > -1:
                if self.totalSize > self._stopSize:
                    return
Esempio n. 2
0
def getsize(path):
    """Return the actual file size considering spare files
       and symlinks"""
    if 'posix' == os.name:
        try:
            __stat = os.lstat(path)
        except OSError as e:
            # OSError: [Errno 13] Permission denied
            # can happen when a regular user is trying to find the size of /var/log/hp/tmp
            # where /var/log/hp is 0774 and /var/log/hp/tmp is 1774
            if errno.EACCES == e.errno:
                return 0
            raise
        return __stat.st_blocks * 512
    if 'nt' == os.name:
        # On rare files os.path.getsize() returns access denied, so first
        # try FindFilesW.
        # Also, apply prefix to use extended-length paths to support longer
        # filenames.
        finddata = win32file.FindFilesW(extended_path(path))
        if not finddata:
            # FindFilesW does not work for directories, so fall back to
            # getsize()
            return os.path.getsize(path)
        else:
            size = (finddata[0][4] * (0xffffffff + 1)) + finddata[0][5]
            return size
    return os.path.getsize(path)
def getNamedPipes(pipeFile):
	file_list = []
	for file in win32file.FindFilesW("\\\\.\\pipe\\*{}".format(pipeFile)):
		if file[8].endswith("\\{}".format(pipeFile)):
			file_list.append(os.path.join("\\\\.\\pipe\\", file[8]))
	return file_list

# for pipe in getNamedPipes("myPET.mga"):
# 	print(pipe)
 def testIter(self):
     dir = os.path.join(os.getcwd(), "*")
     files = win32file.FindFilesW(dir)
     set1 = set()
     set1.update(files)
     set2 = set()
     for file in win32file.FindFilesIterator(dir):
         set2.add(file)
     assert len(set2) > 5, "This directory has less than 5 files!?"
     self.failUnlessEqual(set1, set2)
def get_dir_size(path):
    total_size = 0
    if platform.system() == 'Windows':
        if os.path.isdir(path):
            items = win32file.FindFilesW(
                path + '\\*')  # Add the size or perform recursion on folders.
            for item in items:
                size = item[5]
                total_size += size
    return total_size
Esempio n. 6
0
    def _getSize(self, path):
        """
        This private method calculates the total size
        of a folder or volume, and accepts a UNC or
        local path.
        """

        if self.verbose: print path

        # Get the list of files and folders.
        try:
            items = _win32file.FindFilesW(path + "\\*")
        except _win32file.error, details:
            self.errors[path] = str(details[-1])
            return
Esempio n. 7
0
def Get_PDB_Windows_Filename ( FileName ) :
  """
On windows systems,
  Translates the Filename to the correct case
  the preceding absolute or relative path is converted to lower case !!
  Used to translate filenames coming from PDB and similar packages
On other OS, it just returns the unmodified string
  """
  if os.name == 'nt' :
    """
    # path will be translated to lowercase
    # and we want only forward slashes
    FileName = FileName.lower ().replace ( '\\', '/' )

    # Do a search with some degrees of freedom
    # otherwise glob.glob just returns the original string !!
    Result = glob.glob ( FileName [:-1] + '*')

    if Result:
      for R in Result :
        if R.lower().replace( '\\', '/' ) == FileName :
          return R.replace ( '\\', '/' )
    """
    #install pywin32 before
    import win32file
    filename = FileName.lower ().replace ( '\\', '/' )
    Path, File = path_split ( filename )
    try:
      File = win32file.FindFilesW ( FileName )
    except :
      return None #FileName
    if Path :
      Path += '/'
    #print 'PPBBDD',FileName, Path, File
    if File :
      return Path.lower() + File[0] [8]
    else :
      return FileName

  return FileName
Esempio n. 8
0
        try:
            __stat = os.lstat(path)
        except OSError, e:
            # OSError: [Errno 13] Permission denied
            # can happen when a regular user is trying to find the size of /var/log/hp/tmp
            # where /var/log/hp is 0774 and /var/log/hp/tmp is 1774
            if errno.EACCES == e.errno:
                return 0
            raise
        return __stat.st_blocks * 512
    if 'nt' == os.name:
        # On rare files os.path.getsize() returns access denied, so first
        # try FindFilesW.
        # Also, apply prefix to use extended-length paths to support longer
        # filenames.
        finddata = win32file.FindFilesW(extended_path(path))
        if finddata == []:
            # FindFilesW does not work for directories, so fall back to
            # getsize()
            return os.path.getsize(path)
        else:
            size = (finddata[0][4] * (0xffffffff + 1)) + finddata[0][5]
            return size
    return os.path.getsize(path)


def getsizedir(path):
    """Return the size of the contents of a directory"""
    total_bytes = 0
    for node in children_in_directory(path, list_directories=False):
        total_bytes += getsize(node)
Esempio n. 9
0
       and symlinks"""
    if 'posix' == os.name:
        try:
            __stat = os.lstat(path)
        except OSError, e:
            # OSError: [Errno 13] Permission denied
            # can happen when a regular user is trying to find the size of /var/log/hp/tmp
            # where /var/log/hp is 0774 and /var/log/hp/tmp is 1774
            if errno.EACCES == e.errno:
                return 0
            raise
        return __stat.st_blocks * 512
    if 'nt' == os.name:
        # On rare files os.path.getsize() returns access denied, so try
        # FindFilesW instead
        finddata = win32file.FindFilesW(path)
        if finddata == []:
            # FindFilesW doesn't work for directories, so fall back to getsize()
            return os.path.getsize(path)
        else:
            size = (finddata[0][4] * (0xffffffff + 1)) + finddata[0][5]
            return size
    return os.path.getsize(path)


def getsizedir(path):
    """Return the size of the contents of a directory"""
    total_bytes = 0
    for node in children_in_directory(path, list_directories=False):
        total_bytes += getsize(node)
    return total_bytes
Esempio n. 10
0
def find_files(path):
    # Windows API call
    lst = win32file.FindFilesW(path)

    # Convert find data to a list of dict
    return list(map(find_data_to_dict, lst))