QStorageInfo¶
Provides information about currently mounted storage and drives. More…
Synopsis¶
Functions¶
def
__eq__
(, second)def
__ne__
(, second)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
refresh
()def
rootPath
()def
setPath
(path)def
subvolume
()def
swap
(other)
Static functions¶
def
mountedVolumes
()def
root
()
Detailed Description¶
Allows retrieving information about the volume’s space, its mount point, label, and filesystem name.
You can create an instance of
QStorageInfo
by passing the path to the volume’s mount point as a constructor parameter, or you can set it using thesetPath()
method. The staticmountedVolumes()
method can be used to get the list of all mounted filesystems.
QStorageInfo
always caches the retrieved information, but you can callrefresh()
to invalidate the cache.The following example retrieves the most common information about the root volume of the system, and prints information about it.
QStorageInfo storage = QStorageInfo::root(); qDebug() << storage.rootPath(); if (storage.isReadOnly()) qDebug() << "isReadOnly:" << storage.isReadOnly(); qDebug() << "name:" << storage.name(); qDebug() << "fileSystemType:" << storage.fileSystemType(); qDebug() << "size:" << storage.bytesTotal()/1000/1000 << "MB"; qDebug() << "availableSize:" << storage.bytesAvailable()/1000/1000 << "MB";
- class PySide2.QtCore.QStorageInfo¶
PySide2.QtCore.QStorageInfo(dir)
PySide2.QtCore.QStorageInfo(other)
PySide2.QtCore.QStorageInfo(path)
- param dir:
- param path:
str
- param other:
Constructs an empty
QStorageInfo
object.Objects created with the default constructor will be invalid and therefore not ready for use.
- PySide2.QtCore.QStorageInfo.blockSize()¶
- Return type:
int
Returns the optimal transfer block size for this filesystem.
Returns -1 if
QStorageInfo
could not determine the size or if theQStorageInfo
object is not valid.
- PySide2.QtCore.QStorageInfo.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
QStorageInfo
object is not valid.See also
- PySide2.QtCore.QStorageInfo.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
QStorageInfo
object is not valid.See also
- PySide2.QtCore.QStorageInfo.bytesTotal()¶
- Return type:
int
Returns the total volume size in bytes.
Returns -1 if
QStorageInfo
object is not valid.See also
- PySide2.QtCore.QStorageInfo.device()¶
- Return type:
Returns the device for this volume.
For example, on Unix filesystems (including macOS), this returns the devpath like
/dev/sda0
for local storages. On Windows, it returns the UNC path starting with\\\\?\\
for local storages (in other words, the volume GUID).See also
- PySide2.QtCore.QStorageInfo.displayName()¶
- Return type:
str
Returns the volume’s name, if available, or the root path if not.
- PySide2.QtCore.QStorageInfo.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 namedntfs-3g
orfuseblk
.See also
- PySide2.QtCore.QStorageInfo.isReadOnly()¶
- Return type:
bool
Returns true if the current filesystem is protected from writing; false otherwise.
- PySide2.QtCore.QStorageInfo.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()
, andbytesAvailable()
will return invalid data until the volume is ready.See also
- PySide2.QtCore.QStorageInfo.isRoot()¶
- Return type:
bool
Returns true if this
QStorageInfo
represents 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
- PySide2.QtCore.QStorageInfo.isValid()¶
- Return type:
bool
Returns true if the
QStorageInfo
specified byrootPath
exists and is mounted correctly.See also
- static PySide2.QtCore.QStorageInfo.mountedVolumes()¶
- Return type:
Returns the list of
QStorageInfo
objects 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.
foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) { if (storage.isValid() && storage.isReady()) { if (!storage.isReadOnly()) { // ... } } }
See also
- PySide2.QtCore.QStorageInfo.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
udev
to be present in the system.See also
- PySide2.QtCore.QStorageInfo.__ne__(second)¶
- Parameters:
second –
PySide2.QtCore.QStorageInfo
- Return type:
bool
- PySide2.QtCore.QStorageInfo.__eq__(second)¶
- Parameters:
second –
PySide2.QtCore.QStorageInfo
- Return type:
bool
- PySide2.QtCore.QStorageInfo.refresh()¶
Resets
QStorageInfo
‘s internal cache.QStorageInfo
caches information about storage to speed up performance.QStorageInfo
retrieves information during object construction and/or when calling thesetPath()
method. You have to manually reset the cache by calling this function to update storage information.
- static PySide2.QtCore.QStorageInfo.root()¶
- Return type:
Returns a
QStorageInfo
object 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
- PySide2.QtCore.QStorageInfo.rootPath()¶
- Return type:
str
Returns the mount point of the filesystem this
QStorageInfo
object represents.On Windows, it returns the volume letter in case the volume is not mounted to a directory.
Note that the value returned by 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’ tosetPath()
, then this method will return ‘/’.
- PySide2.QtCore.QStorageInfo.setPath(path)¶
- Parameters:
path – str
Sets this
QStorageInfo
object to the filesystem mounted wherepath
is located.path
can either be a root path of the filesystem, a directory, or a file within that filesystem.See also
- PySide2.QtCore.QStorageInfo.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. If the subvolume could be detected, it is returned here. 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
- PySide2.QtCore.QStorageInfo.swap(other)¶
- Parameters:
other –
PySide2.QtCore.QStorageInfo
Swaps this volume info with
other
. This function is very fast and never fails.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.