PySide6.QtCore.QStorageInfo¶
- class QStorageInfo¶
- Provides information about currently mounted storage and drives. More… - Synopsis¶- Methods¶- def - __init__()
- def - blockSize()
- def - bytesAvailable()
- def - bytesFree()
- def - bytesTotal()
- def - device()
- def - displayName()
- def - fileSystemType()
- def - isReadOnly()
- def - isReady()
- def - isRoot()
- def - isValid()
- def - name()
- def - __ne__()
- def - __eq__()
- def - refresh()
- def - rootPath()
- def - setPath()
- def - subvolume()
- def - swap()
 - Static functions¶- def - mountedVolumes()
- def - root()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Allows retrieving information about the volume’s space, its mount point, label, and filesystem name. - You can create an instance of - QStorageInfoby passing the path to the volume’s mount point as a constructor parameter, or you can set it using the- setPath()method. The static- mountedVolumes()method can be used to get the list of all mounted filesystems.- QStorageInfoalways caches the retrieved information, but you can call- refresh()to invalidate the cache.- The following example retrieves the most common information about the root volume of the system, and prints information about it. - storage = QStorageInfo.root() print(storage.rootPath()) if storage.isReadOnly(): print("isReadOnly:", storage.isReadOnly()) print("name:", storage.name()) print("fileSystemType:", storage.fileSystemType()) print("size:", storage.bytesTotal()/1000/1000, "MB") print("availableSize:", storage.bytesAvailable()/1000/1000, "MB") - __init__()¶
 - Constructs an empty - QStorageInfoobject.- Objects created with the default constructor will be invalid and therefore not ready for use. - __init__(dir)
- Parameters:
- dir – - QDir
 
 - Constructs a new - QStorageInfoobject that gives information about the volume containing the- dirfolder.- __init__(other)
- Parameters:
- other – - QStorageInfo
 
 - Constructs a new - QStorageInfoobject that is a copy of the- other- QStorageInfoobject.- __init__(path)
- Parameters:
- path – str 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Constructs a new - QStorageInfoobject that gives information about the volume mounted at- path.- If you pass a directory or file, the - QStorageInfoobject will refer to the volume where this directory or file is located. You can check if the created object is correct using the- isValid()method.- The following example shows how to get the volume on which the application is located. It is recommended to always check that the volume is ready and valid. - storage = QStorageInfo(qApp.applicationDirPath()) if storage.isValid() and storage.isReady(): # ... - See also - blockSize()¶
- Return type:
- int 
 
 - Returns the optimal transfer block size for this filesystem. - Returns -1 if - QStorageInfocould not determine the size or if the- QStorageInfoobject is not valid.- bytesAvailable()¶
- Return type:
- int 
 
 - Returns the size (in bytes) available for the current user. It returns the total size available if the user is the root user or a system administrator. - This size can be less than or equal to the free size returned by - bytesFree()function.- Returns -1 if - QStorageInfoobject is not valid.- See also - bytesFree()¶
- Return type:
- int 
 
 - Returns the number of free bytes in a volume. Note that if there are quotas on the filesystem, this value can be larger than the value returned by - bytesAvailable().- Returns -1 if - QStorageInfoobject is not valid.- See also - bytesTotal()¶
- Return type:
- int 
 
 - Returns the total volume size in bytes. - Returns -1 if - QStorageInfoobject is not valid.- See also - device()¶
- Return type:
 
 - Returns the device for this volume. - For example, on Unix filesystems (including macOS), this returns the devpath like - /dev/sda0for local storages. On Windows, it returns the UNC path starting with- \\\\?\\for local storages (in other words, the volume GUID).- See also - displayName()¶
- Return type:
- str 
 
 - Returns the volume’s name, if available, or the root path if not. - fileSystemType()¶
- Return type:
 
 - Returns the type name of the filesystem. - This is a platform-dependent function, and filesystem names can vary between different operating systems. For example, on Windows filesystems they can be named - NTFS, and on Linux they can be named- ntfs-3gor- fuseblk.- See also - isReadOnly()¶
- Return type:
- bool 
 
 - Returns true if the current filesystem is protected from writing; false otherwise. - isReady()¶
- Return type:
- bool 
 
 - Returns true if the current filesystem is ready to work; false otherwise. For example, false is returned if the CD volume is not inserted. - Note that - fileSystemType(),- name(),- bytesTotal(),- bytesFree(), and- bytesAvailable()will return invalid data until the volume is ready.- See also - isRoot()¶
- Return type:
- bool 
 
 - Returns true if this - QStorageInforepresents the system root volume; false otherwise.- On Unix filesystems, the root volume is a volume mounted on - /. On Windows, the root volume is the volume where the OS is installed.- See also - isValid()¶
- Return type:
- bool 
 
 - Returns true if the - QStorageInfospecified by- rootPathexists and is mounted correctly.- See also - static mountedVolumes()¶
- Return type:
- .list of QStorageInfo 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns the list of - QStorageInfoobjects that corresponds to the list of currently mounted filesystems.- On Windows, this returns the drives visible in the My Computer folder. On Unix operating systems, it returns the list of all mounted filesystems (except for pseudo filesystems). - Returns all currently mounted filesystems by default. - The example shows how to retrieve all available filesystems, skipping read-only ones. - for storage in QStorageInfo.mountedVolumes(): if storage.isValid() and storage.isReady(): if not storage.isReadOnly(): # ... - See also - name()¶
- Return type:
- str 
 
 - Returns the human-readable name of a filesystem, usually called - label.- Not all filesystems support this feature. In this case, the value returned by this method could be empty. An empty string is returned if the file system does not support labels, or if no label is set. - On Linux, retrieving the volume’s label requires - udevto be present in the system.- See also - __ne__(rhs)¶
- Parameters:
- rhs – - QStorageInfo
- Return type:
- bool 
 
 - Returns - trueif the- QStorageInfoobject- lhsrefers to a different drive or volume than the- QStorageInfoobject- rhs; otherwise returns- false.- __eq__(rhs)¶
- Parameters:
- rhs – - QStorageInfo
- Return type:
- bool 
 
 - Returns - trueif the- QStorageInfoobject- lhsrefers to the same drive or volume as the- QStorageInfoobject- rhs; otherwise it returns- false.- Note that the result of comparing two invalid - QStorageInfoobjects is always positive.- refresh()¶
 - Resets - QStorageInfo‘s internal cache.- QStorageInfocaches information about storage to speed up performance.- QStorageInforetrieves information during object construction and/or when calling the- setPath()method. You have to manually reset the cache by calling this function to update storage information.- static root()¶
- Return type:
 
 - Returns a - QStorageInfoobject that represents the system root volume.- On Unix systems this call returns the root (‘/’) volume; in Windows the volume where the operating system is installed. - See also - rootPath()¶
- Return type:
- str 
 
 - Returns the mount point of the filesystem this - QStorageInfoobject represents.- On Windows, it returns the volume letter in case the volume is not mounted to a directory. - Note that the value returned by rootPath() is the real mount point of a volume, and may not be equal to the value passed to the constructor or - setPath()method. For example, if you have only the root volume in the system, and pass ‘/directory’ to- setPath(), then this method will return ‘/’.- setPath(path)¶
- Parameters:
- path – str 
 
 - Sets this - QStorageInfoobject to the filesystem mounted where- pathis located.- pathcan either be a root path of the filesystem, a directory, or a file within that filesystem.- See also - subvolume()¶
- Return type:
 
 - Returns the subvolume name for this volume. - Some filesystem types allow multiple subvolumes inside one device, which may be mounted in different paths (e.g. ‘bind’ mounts on Unix, or Btrfs filesystem subvolumes). If the subvolume could be detected, its name is returned by this function. The format of the subvolume name is specific to each filesystem type. - If this volume was not mounted from a subvolume of a larger filesystem or if the subvolume could not be detected, this function returns an empty byte array. - See also - swap(other)¶
- Parameters:
- other – - QStorageInfo
 
 - Swaps this volume info with - other. This operation is very fast and never fails.