PySide6.QtCore.QFileInfo¶
- class QFileInfo¶
- The - QFileInfoclass provides an OS-independent API to retrieve information about file system entries. More…- Synopsis¶- Methods¶- def - __init__()
- def - __reduce__()
- def - absoluteDir()
- def - absolutePath()
- def - baseName()
- def - birthTime()
- def - bundleName()
- def - caching()
- def - canonicalPath()
- def - completeSuffix()
- def - dir()
- def - exists()
- def - fileName()
- def - filePath()
- def - fileTime()
- def - group()
- def - groupId()
- def - isAbsolute()
- def - isAlias()
- def - isBundle()
- def - isDir()
- def - isExecutable()
- def - isFile()
- def - isHidden()
- def - isJunction()
- def - isNativePath()
- def - isReadable()
- def - isRelative()
- def - isRoot()
- def - isShortcut()
- def - isSymLink()
- def - isSymbolicLink()
- def - isWritable()
- def - junctionTarget()
- def - lastModified()
- def - lastRead()
- def - makeAbsolute()
- def - __ne__()
- def - __eq__()
- def - owner()
- def - ownerId()
- def - path()
- def - permission()
- def - permissions()
- def - readSymLink()
- def - refresh()
- def - setCaching()
- def - setFile()
- def - size()
- def - stat()
- def - suffix()
- def - swap()
- def - symLinkTarget()
 - Static functions¶- def - exists()
 - 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. - QFileInfoprovides information about a file system entry, such as its name, path, access rights and whether it is a regular file, directory or symbolic link. The entry’s size and last modified/read times are also available.- QFileInfocan also be used to obtain information about a Qt resource .- A - QFileInfocan point to a file system entry with either an absolute or a relative path:- On Unix, absolute paths begin with the directory separator - '/'. On Windows, absolute paths begin with a drive specification (for example,- D:/).
- Relative paths begin with a directory name or a regular file name and specify a file system entry’s path relative to the current working directory. 
 - An example of an absolute path is the string - "/tmp/quartz". A relative path may look like- "src/fatlib". You can use the function- isRelative()to check whether a- QFileInfois using a relative or an absolute path. You can call the function- makeAbsolute()to convert a relative- QFileInfo‘s path to an absolute path.- Note - Paths starting with a colon (:) are always considered absolute, as they denote a - QResource.- The file system entry path that the - QFileInfoworks on is set in the constructor or later with- setFile(). Use- exists()to see if the entry actually exists and- size()to get its size.- The file system entry’s type is obtained with - isFile(),- isDir(), and- isSymLink(). The- symLinkTarget()function provides the absolute path of the target the symlink points to.- The path elements of the file system entry can be extracted with - path()and- fileName(). The- fileName()‘s parts can be extracted with- baseName(),- suffix(), or- completeSuffix().- QFileInfoobjects referring to directories created by Qt classes will not have a trailing directory separator- '/'. If you wish to use trailing separators in your own file info objects, just append one to the entry’s path given to the constructors or- setFile().- Date and time related information are returned by - birthTime(),- fileTime(),- lastModified(),- lastRead(), and- metadataChangeTime(). Information about access permissions can be obtained with- isReadable(),- isWritable(), and- isExecutable(). Ownership information can be obtained with- owner(),- ownerId(),- group(), and- groupId(). You can also examine permissions and ownership in a single statement using the- permission()function.- Symbolic Links and Shortcuts¶- On Unix (including macOS and iOS), the property getter functions in this class return the properties such as times and size of the target, not the symlink, because Unix handles symlinks transparently. Opening a symlink using - QFileeffectively opens the link’s target. For example:- #ifdef Q_OS_UNIX info1 = QFileInfo("/home/bob/bin/untabify") info1.isSymLink() # returns true info1.absoluteFilePath() # returns "/home/bob/bin/untabify" info1.size() # returns 56201 info1.symLinkTarget() # returns "/opt/pretty++/bin/untabify" info2 = QFileInfo(info1.symLinkTarget()) info2.isSymLink() # returns false info2.absoluteFilePath() # returns "/opt/pretty++/bin/untabify" info2.size() # returns 56201 #endif - On Windows, shortcuts ( - .lnkfiles) are currently treated as symlinks. As on Unix systems, the property getters return the size of the target, not the- .lnkfile itself. This behavior is deprecated and will likely be removed in a future version of Qt, after which- .lnkfiles will be treated as regular files.- #ifdef Q_OS_WIN info1 = QFileInfo("C:\\Users\\Bob\\untabify.lnk") info1.isSymLink() # returns true info1.absoluteFilePath() # returns "C:/Users/Bob/untabify.lnk" info1.size() # returns 63942 info1.symLinkTarget() # returns "C:/Pretty++/untabify" info2 = QFileInfo(info1.symLinkTarget()) info2.isSymLink() # returns false info2.absoluteFilePath() # returns "C:/Pretty++/untabify" info2.size() # returns 63942 #endif - NTFS permissions¶- On NTFS file systems, ownership and permissions checking is disabled by default for performance reasons. To enable it, include the following line: - Q_CORE_EXPORT = extern() - Permission checking is then turned on and off by incrementing and decrementing - qt_ntfs_permission_lookupby 1.- qt_ntfs_permission_lookup++ # turn checking on qt_ntfs_permission_lookup-- # turn it off again - Note - Since this is a non-atomic global variable, it is only safe to increment or decrement - qt_ntfs_permission_lookupbefore any threads other than the main thread have started or after every thread other than the main thread has ended.- Note - From Qt 6.6 the variable - qt_ntfs_permission_lookupis deprecated. Please use the following alternatives.- The safe and easy way to manage permission checks is to use the RAII class - QNtfsPermissionCheckGuard.- def complexFunction(): QNtfsPermissionCheckGuard permissionGuard # check is enabled # do complex things here that need permission check enabled } // as the guard goes out of scope the check is disabled - If you need more fine-grained control, it is possible to manage the permission with the following functions instead: - qAreNtfsPermissionChecksEnabled() # check status qEnableNtfsPermissionChecks() # turn checking on qDisableNtfsPermissionChecks() # turn it off again - Performance Considerations¶- Some of - QFileInfo‘s functions have to query the file system, but for performance reasons, some functions only operate on the path string. For example: To return the absolute path of a relative entry’s path,- absolutePath()has to query the file system. The- path()function, however, can work on the file name directly, and so it is faster.- QFileInfoalso caches information about the file system entry it refers to. Because the file system can be changed by other users or programs, or even by other parts of the same program, there is a function that refreshes the information stored in- QFileInfo, namely- refresh(). To switch off a- QFileInfo‘s caching (that is, force it to query the underlying file system every time you request information from it), call- setCaching(false).- Fetching information from the file system is typically done by calling (possibly) expensive system functions, so - QFileInfo(depending on the implementation) might not fetch all the information from the file system at construction. To make sure that all information is read from the file system immediately, use the- stat()member function.- birthTime(),- fileTime(),- lastModified(),- lastRead(), and- metadataChangeTime()return times in local time by default. Since native file system API typically uses UTC, this requires a conversion. If you don’t actually need the local time, you can avoid this by requesting the time in- UTCdirectly.- Platform Specific Issues¶- On Android, some limitations apply when dealing with content URIs : - Access permissions might be needed by prompting the user through the QFileDialog which implements Android’s native file picker . 
- Aim to follow the Scoped storage guidelines, such as using app specific directories instead of other public external directories. For more information, also see storage best practices . 
- Due to the design of Qt APIs (e.g. - QFile), it’s not possible to fully integrate the latter APIs with Android’s MediaStore APIs.
 - __init__()¶
 - Constructs an empty - QFileInfoobject that doesn’t refer to any file system entry.- See also - __init__(file)
- Parameters:
- file – - QFileDevice
 
 - Constructs a new - QFileInfothat gives information about file- file.- If the - filehas a relative path, the- QFileInfowill also have a relative path.- See also - __init__(fileinfo)
- Parameters:
- fileinfo – - QFileInfo
 
 - Constructs a new - QFileInfothat is a copy of the given- fileinfo.- __init__(file)
- Parameters:
- file – str 
 
 - Constructs a - QFileInfothat gives information about a file system entry located at- paththat can be absolute or relative.- If - pathis relative, the- QFileInfowill also have a relative path.- __init__(dir, file)
- Parameters:
- dir – - QDir
- file – str 
 
 
 - Constructs a new - QFileInfothat gives information about the given file system entry- paththat is relative to the directory- dir.- If - dirhas a relative path, the- QFileInfowill also have a relative path.- If - pathis absolute, then the directory specified by- dirwill be disregarded.- See also - __reduce__()¶
- Return type:
- str 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns a - QDirobject representing the absolute path of the parent directory of the file system entry that this- QFileInforefers to.- # Given a current working directory of "/home/user/Documents/memos/" info1 = QFileInfo("relativeFile") print(info1.absolutePath() # "/home/user/Documents/memos/") print(info1.baseName() # "relativeFile") print(info1.absoluteDir() # QDir("/home/user/Documents/memos")) print(info1.absoluteDir().path() # "/home/user/Documents/memos") # A QFileInfo on a dir info2 = QFileInfo("/home/user/Documents/memos") print(info2.absolutePath() # "/home/user/Documents") print(info2.baseName() # "memos") print(info2.absoluteDir() # QDir("/home/user/Documents")) print(info2.absoluteDir().path() # "/home/user/Documents") - See also - absoluteFilePath()¶
- Return type:
- str 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns the absolute full path to the file system entry this - QFileInforefers to, including the entry’s name.- On Unix, absolute paths begin with the directory separator - '/'. On Windows, absolute paths begin with a drive specification (for example,- D:/).- On Windows, the paths of network shares that are not mapped to a drive letter begin with - //sharename/.- QFileInfowill uppercase drive letters. Note that- QDirdoes not do this. The code snippet below shows this.- fi = QFileInfo("c:/temp/foo") print(fi.absoluteFilePath() # "C:/temp/foo") - This function returns the same as - filePath(), unless- isRelative()is true. In contrast to- canonicalFilePath(), symbolic links or redundant “.” or “..” elements are not necessarily removed.- absolutePath()¶
- Return type:
- str 
 
 - Returns the absolute path of the file system entry this - QFileInforefers to, excluding the entry’s name.- On Unix, absolute paths begin with the directory separator - '/'. On Windows, absolute paths begin with a drive specification (for example,- D:/).- On Windows, the paths of network shares that are not mapped to a drive letter begin with - //sharename/.- In contrast to - canonicalPath()symbolic links or redundant “.” or “..” elements are not necessarily removed.- Warning - If - filePath()is empty the behavior of this function is undefined.- baseName()¶
- Return type:
- str 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns the base name of the file without the path. - The base name consists of all characters in the file up to (but not including) the first ‘.’ character. - Example: - fi = QFileInfo("/tmp/archive.tar.gz") base = fi.baseName() # base = "archive" - The base name of a file is computed equally on all platforms, independent of file naming conventions (e.g., “.bashrc” on Unix has an empty base name, and the suffix is “bashrc”). - Returns the date and time when the file was created (born), in local time. - If the file birth time is not available, this function returns an invalid - QDateTime.- If the file is a symlink, this function returns information about the target, not the symlink. - This function overloads QFileInfo::birthTime(const - QTimeZone&tz), and returns the same as- birthTime(QTimeZone::LocalTime).- Returns the date and time when the file was created (born). - The returned time is in the time zone specified by - tz. For example, you can use- LocalTimeor- UTCto get the time in the Local time zone or UTC, respectively. Since native file system API typically uses UTC, using- UTCis often faster, as it does not require any conversions.- If the file birth time is not available, this function returns an invalid - QDateTime.- If the file is a symlink, this function returns information about the target, not the symlink. - See also - lastModified(const QTimeZone &)- lastRead(const QTimeZone &)- metadataChangeTime(const QTimeZone &)- FileTime, const QTimeZone &)- bundleName()¶
- Return type:
- str 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns the name of the bundle. - On macOS and iOS this returns the proper localized name for a bundle if the path - isBundle(). On all other platforms an empty- QStringis returned.- Example: - fi = QFileInfo("/Applications/Safari.app") bundle = fi.bundleName() # name = "Safari" - See also - caching()¶
- Return type:
- bool 
 
 - Returns - trueif caching is enabled; otherwise returns- false.- See also - canonicalFilePath()¶
- Return type:
- str 
 
 - Returns the file system entry’s canonical path, including the entry’s name, that is, an absolute path without symbolic links or redundant - '.'or- '..'elements.- If the entry does not exist, canonicalFilePath() returns an empty string. - See also - canonicalPath()¶
- Return type:
- str 
 
 - Returns the file system entry’s canonical path (excluding the entry’s name), i.e. an absolute path without symbolic links or redundant “.” or “..” elements. - If the entry does not exist, this method returns an empty string. - See also - completeBaseName()¶
- Return type:
- str 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns the complete base name of the file without the path. - The complete base name consists of all characters in the file up to (but not including) the last ‘.’ character. - Example: - fi = QFileInfo("/tmp/archive.tar.gz") base = fi.completeBaseName() # base = "archive.tar" - See also - completeSuffix()¶
- Return type:
- str 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns the complete suffix (extension) of the file. - The complete suffix consists of all characters in the file after (but not including) the first ‘.’. - Example: - fi = QFileInfo("/tmp/archive.tar.gz") ext = fi.completeSuffix() # ext = "tar.gz" - See also - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns a - QDirobject representing the path of the parent directory of the file system entry that this- QFileInforefers to.- Note - The - QDirreturned always corresponds to the object’s parent directory, even if the- QFileInforepresents a directory.- For each of the following, dir() returns the - QDir- "~/examples/191697".- fileInfo1 = QFileInfo("~/examples/191697/.") fileInfo2 = QFileInfo("~/examples/191697/..") fileInfo3 = QFileInfo("~/examples/191697/main.cpp") - For each of the following, dir() returns the - QDir- ".".- fileInfo4 = QFileInfo(".") fileInfo5 = QFileInfo("..") fileInfo6 = QFileInfo("main.cpp") - exists()¶
- Return type:
- bool 
 
 - Returns - trueif the file system entry this- QFileInforefers to exists; otherwise returns- false.- Note - If the entry is a symlink that points to a non-existing target, this method returns - false.- static exists(file)
- Parameters:
- file – str 
- Return type:
- bool 
 
 - Returns - trueif the file system entry- pathexists; otherwise returns- false.- Note - If - pathis a symlink that points to a non-existing target, this method returns- false.- Note - Using this function is faster than using - QFileInfo(path).exists()for file system access.- fileName()¶
- Return type:
- str 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns the name of the file system entry this - QFileInforefers to, excluding the path.- Example: - fi = QFileInfo("/tmp/archive.tar.gz") name = fi.fileName() # name = "archive.tar.gz" - Note - If this - QFileInfois given a path ending with a directory separator- '/', the entry’s name part is considered empty.- See also - filePath()¶
- Return type:
- str 
 
 - Returns the path of the file system entry this - QFileInforefers to; the path may be absolute or relative.- Returns the file time specified by - time.- If the time cannot be determined, an invalid date time is returned. - If the file is a symlink, this function returns information about the target, not the symlink. - This function overloads - FileTime, const QTimeZone &), and returns the same as- fileTime(time, QTimeZone::LocalTime).- Returns the file time specified by - time.- The returned time is in the time zone specified by - tz. For example, you can use- LocalTimeor- UTCto get the time in the Local time zone or UTC, respectively. Since native file system API typically uses UTC, using- UTCis often faster, as it does not require any conversions.- If the time cannot be determined, an invalid date time is returned. - If the file is a symlink, this function returns information about the target, not the symlink. - See also - birthTime(const QTimeZone &)- lastModified(const QTimeZone &)- lastRead(const QTimeZone &)- metadataChangeTime(const QTimeZone &)- isValid()- group()¶
- Return type:
- str 
 
 - Returns the group of the file. On Windows, on systems where files do not have groups, or if an error occurs, an empty string is returned. - This function can be time consuming under Unix (in the order of milliseconds). - If the file is a symlink, this function returns information about the target, not the symlink. - groupId()¶
- Return type:
- int 
 
 - Returns the id of the group the file belongs to. - On Windows and on systems where files do not have groups this function always returns (uint) -2. - If the file is a symlink, this function returns information about the target, not the symlink. - isAbsolute()¶
- Return type:
- bool 
 
 - Returns - trueif the file system entry’s path is absolute, otherwise returns- false(that is, the path is relative).- Note - Paths starting with a colon (:) are always considered absolute, as they denote a - QResource.- See also - isAlias()¶
- Return type:
- bool 
 
 - Returns - trueif this object points to an alias; otherwise returns- false.- Aliases only exist on macOS. They are treated as regular files, so opening an alias will open the file itself. In order to open the file or directory an alias references use - symLinkTarget().- Note - Even if an alias points to a non existing file, isAlias() returns true. - See also - isBundle()¶
- Return type:
- bool 
 
 - Returns - trueif this object points to a bundle or to a symbolic link to a bundle on macOS and iOS; otherwise returns- false.- If the file is a symlink, this function returns information about the target, not the symlink. - See also - isDir()¶
- Return type:
- bool 
 
 - Returns - trueif this object points to a directory or to a symbolic link to a directory. Returns- falseif the object points to something that is not a directory (such as a file) or that does not exist.- If the file is a symlink, this function returns information about the target, not the symlink. - See also - isExecutable()¶
- Return type:
- bool 
 
 - Returns - trueif the file system entry this- QFileInforefers to is executable; otherwise returns- false.- If the file is a symlink, this function returns information about the target, not the symlink. - See also - isFile()¶
- Return type:
- bool 
 
 - Returns - trueif this object points to a file or to a symbolic link to a file. Returns- falseif the object points to something that is not a file (such as a directory) or that does not exist.- If the file is a symlink, this function returns information about the target, not the symlink. - See also - isHidden()¶
- Return type:
- bool 
 
 - Returns - trueif the file system entry this- QFileInforefers to is `hidden’; otherwise returns- false.- Note - This function returns - truefor the special entries “.” and “..” on Unix, even though- entryListtreats them as shown. And note that, since this function inspects the file name, on Unix it will inspect the name of the symlink, if this file is a symlink, not the target’s name.- On Windows, this function returns - trueif the target file is hidden (not the symlink).- isJunction()¶
- Return type:
- bool 
 
 - Returns - trueif the object points to a junction; otherwise returns- false.- Junctions only exist on Windows’ NTFS file system, and are typically created by the - mklinkcommand. They can be thought of as symlinks for directories, and can only be created for absolute paths on the local volume.- isNativePath()¶
- Return type:
- bool 
 
 - Returns - trueif the file path can be used directly with native APIs. Returns- falseif the file is otherwise supported by a virtual file system inside Qt, such as the Qt Resource System .- Note - Native paths may still require conversion of path separators and character encoding, depending on platform and input requirements of the native API. - isReadable()¶
- Return type:
- bool 
 
 - Returns - trueif the user can read the file system entry this- QFileInforefers to; otherwise returns- false.- If the file is a symlink, this function returns information about the target, not the symlink. - Note - If the - NTFS permissionscheck has not been enabled, the result on Windows will merely reflect whether the entry exists.- See also - isRelative()¶
- Return type:
- bool 
 
 - Returns - trueif the file system entry’s path is relative, otherwise returns- false(that is, the path is absolute).- On Unix, absolute paths begin with the directory separator - '/'. On Windows, absolute paths begin with a drive specification (for example,- D:/).- Note - Paths starting with a colon (:) are always considered absolute, as they denote a - QResource.- See also - isRoot()¶
- Return type:
- bool 
 
 - Returns - trueif the object points to a directory or to a symbolic link to a directory, and that directory is the root directory; otherwise returns- false.- isShortcut()¶
- Return type:
- bool 
 
 - Returns - trueif this object points to a shortcut; otherwise returns- false.- Shortcuts only exist on Windows and are typically - .lnkfiles. For instance, true will be returned for shortcuts (- *.lnkfiles) on Windows, but false will be returned on Unix (including macOS and iOS).- The shortcut (.lnk) files are treated as regular files. Opening those will open the - .lnkfile itself. In order to open the file a shortcut references to, it must uses- symLinkTarget()on a shortcut.- Note - Even if a shortcut (broken shortcut) points to a non existing file, isShortcut() returns true. - See also - isSymLink()¶
- Return type:
- bool 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns - trueif this object points to a symbolic link, shortcut, or alias; otherwise returns- false.- Symbolic links exist on Unix (including macOS and iOS) and Windows and are typically created by the - ln -sor- mklinkcommands, respectively. Opening a symbolic link effectively opens the- link's target.- In addition, true will be returned for shortcuts ( - *.lnkfiles) on Windows, and aliases on macOS. This behavior is deprecated and will likely change in a future version of Qt. Opening a shortcut or alias will open the- .lnkor alias file itself.- Example: - info = QFileInfo(fileName) if info.isSymLink(): fileName = info.symLinkTarget() - Note - exists()returns- trueif the symlink points to an existing target, otherwise it returns- false.- See also - isSymbolicLink()¶
- Return type:
- bool 
 
 - Returns - trueif this object points to a symbolic link; otherwise returns- false.- Symbolic links exist on Unix (including macOS and iOS) and Windows (NTFS-symlink) and are typically created by the - ln -sor- mklinkcommands, respectively.- Unix handles symlinks transparently. Opening a symbolic link effectively opens the - link's target.- In contrast to - isSymLink(), false will be returned for shortcuts (- *.lnkfiles) on Windows and aliases on macOS. Use- isShortcut()and- isAlias()instead.- Note - exists()returns- trueif the symlink points to an existing target, otherwise it returns- false.- See also - isWritable()¶
- Return type:
- bool 
 
 - Returns - trueif the user can write to the file system entry this- QFileInforefers to; otherwise returns- false.- If the file is a symlink, this function returns information about the target, not the symlink. - Note - If the - NTFS permissionscheck has not been enabled, the result on Windows will merely reflect whether the entry is marked as Read Only.- See also - junctionTarget()¶
- Return type:
- str 
 
 - Resolves an NTFS junction to the path it references. - Returns the absolute path to the directory an NTFS junction points to, or an empty string if the object is not an NTFS junction. - There is no guarantee that the directory named by the NTFS junction actually exists. - Returns the date and time when the file was last modified. - If the file is a symlink, this function returns information about the target, not the symlink. - This function overloads - lastModified(const QTimeZone &), and returns the same as- lastModified(QTimeZone::LocalTime).- Returns the date and time when the file was last modified. - The returned time is in the time zone specified by - tz. For example, you can use- LocalTimeor- UTCto get the time in the Local time zone or UTC, respectively. Since native file system API typically uses UTC, using- UTCis often faster, as it does not require any conversions.- If the file is a symlink, this function returns information about the target, not the symlink. - See also - birthTime(const QTimeZone &)- lastRead(const QTimeZone &)- metadataChangeTime(const QTimeZone &)- FileTime, const QTimeZone &)- Returns the date and time when the file was last read (accessed). - On platforms where this information is not available, returns the same time as - lastModified().- If the file is a symlink, this function returns information about the target, not the symlink. - This function overloads - lastRead(const QTimeZone &), and returns the same as- lastRead(QTimeZone::LocalTime).- Returns the date and time when the file was last read (accessed). - The returned time is in the time zone specified by - tz. For example, you can use- LocalTimeor- UTCto get the time in the Local time zone or UTC, respectively. Since native file system API typically uses UTC, using- UTCis often faster, as it does not require any conversions.- On platforms where this information is not available, returns the same time as - lastModified().- If the file is a symlink, this function returns information about the target, not the symlink. - See also - birthTime(const QTimeZone &)- lastModified(const QTimeZone &)- metadataChangeTime(const QTimeZone &)- FileTime, const QTimeZone &)- makeAbsolute()¶
- Return type:
- bool 
 
 - If the file system entry’s path is relative, this method converts it to an absolute path and returns - true; if the path is already absolute, this method returns- false.- See also - Returns the date and time when the file’s metadata was last changed, in local time. - A metadata change occurs when the file is first created, but it also occurs whenever the user writes or sets inode information (for example, changing the file permissions). - If the file is a symlink, this function returns information about the target, not the symlink. - This function overloads QFileInfo::metadataChangeTime(const - QTimeZone&tz), and returns the same as- metadataChangeTime(QTimeZone::LocalTime).- See also - Returns the date and time when the file’s metadata was last changed. A metadata change occurs when the file is first created, but it also occurs whenever the user writes or sets inode information (for example, changing the file permissions). - The returned time is in the time zone specified by - tz. For example, you can use- LocalTimeor- UTCto get the time in the Local time zone or UTC, respectively. Since native file system API typically uses UTC, using- UTCis often faster, as it does not require any conversions.- If the file is a symlink, this function returns information about the target, not the symlink. - See also - birthTime(const QTimeZone &)- lastModified(const QTimeZone &)- lastRead(const QTimeZone &)- FileTime time, const QTimeZone &)- Returns - trueif- QFileInfo- lhsrefers to a different file system entry than the one referred to by- rhs; otherwise returns- false.- See also - operator==()- Returns - trueif- QFileInfo- lhsand- QFileInfo- rhsrefer to the same entry on the file system; otherwise returns- false.- Note that the result of comparing two empty - QFileInfoobjects, containing no file system entry references (paths that do not exist or are empty), is undefined.- Warning - This will not compare two different symbolic links pointing to the same target. - Warning - On Windows, long and short paths that refer to the same file system entry are treated as if they referred to different entries. - See also - operator!=()- owner()¶
- Return type:
- str 
 
 - Returns the owner of the file. On systems where files do not have owners, or if an error occurs, an empty string is returned. - This function can be time consuming under Unix (in the order of milliseconds). On Windows, it will return an empty string unless the - NTFS permissionscheck has been enabled.- If the file is a symlink, this function returns information about the target, not the symlink. - ownerId()¶
- Return type:
- int 
 
 - Returns the id of the owner of the file. - On Windows and on systems where files do not have owners this function returns ((uint) -2). - If the file is a symlink, this function returns information about the target, not the symlink. - path()¶
- Return type:
- str 
 
 - Returns the path of the file system entry this - QFileInforefers to, excluding the entry’s name.- Note - If this - QFileInfois given a path ending with a directory separator- '/', the entry’s name part is considered empty. In this case, this function will return the entire path.- permission(permissions)¶
- Parameters:
- permissions – Combination of - Permission
- Return type:
- bool 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Tests for file permissions. The - permissionsargument can be several flags of type QFile::Permissions OR-ed together to check for permission combinations.- On systems where files do not have permissions this function always returns - true.- Note - The result might be inaccurate on Windows if the - NTFS permissionscheck has not been enabled.- Example: - fi = QFileInfo("/tmp/archive.tar.gz") if fi.permission(QFile.WriteUser | QFile.ReadGroup): qWarning("I can change the file; my group can read the file") if fi.permission(QFile.WriteGroup | QFile.WriteOther): qWarning("The group or others can change the file") - If the file is a symlink, this function returns information about the target, not the symlink. - See also - permissions()¶
- Return type:
- Combination of - Permission
 
 - Returns the complete OR-ed together combination of QFile::Permissions for the file. - Note - The result might be inaccurate on Windows if the - NTFS permissionscheck has not been enabled.- If the file is a symlink, this function returns information about the target, not the symlink. - readSymLink()¶
- Return type:
- str 
 
 - Read the path the symlink references. - Returns the raw path referenced by the symbolic link, without resolving a relative path relative to the directory containing the symbolic link. The returned string will only be an absolute path if the symbolic link actually references it as such. Returns an empty string if the object is not a symbolic link. - See also - refresh()¶
 - Refreshes the information about the file system entry this - QFileInforefers to, that is, reads in information from the file system the next time a cached property is fetched.- setCaching(on)¶
- Parameters:
- on – bool 
 
 - If - enableis true, enables caching of file information. If- enableis false caching is disabled.- When caching is enabled, - QFileInforeads the file information from the file system the first time it’s needed, but generally not later.- Caching is enabled by default. - setFile(file)¶
- Parameters:
- file – - QFileDevice
 
 - This is an overloaded function. - Sets the file that the - QFileInfoprovides information about to- file.- If - fileincludes a relative path, the- QFileInfowill also have a relative path.- See also - setFile(file)
- Parameters:
- file – str 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Sets the path of the file system entry that this - QFileInfoprovides information about to- paththat can be absolute or relative.- On Unix, absolute paths begin with the directory separator - '/'. On Windows, absolute paths begin with a drive specification (for example,- D:/).- Relative paths begin with a directory name or a regular file name and specify a file system entry’s path relative to the current working directory. - Example: - info = QFileInfo("/usr/bin/env") path = info.absolutePath() # path = /usr/bin base = info.baseName() # base = env info.setFile("/etc/hosts") path = info.absolutePath() # path = /etc base = info.baseName() # base = hosts - See also - setFile(dir, file)
- Parameters:
- dir – - QDir
- file – str 
 
 
 - This is an overloaded function. - Sets the path of the file system entry that this - QFileInfoprovides information about to- pathin directory- dir.- If - dirhas a relative path, the- QFileInfowill also have a relative path.- If - pathis absolute, then the directory specified by- dirwill be disregarded.- See also - size()¶
- Return type:
- int 
 
 - Returns the file size in bytes. If the file does not exist or cannot be fetched, 0 is returned. - If the file is a symlink, this function returns information about the target, not the symlink. - See also - stat()¶
 - Reads all attributes from the file system. - This is useful when information about the file system is collected in a worker thread, and then passed to the UI in the form of caching - QFileInfoinstances.- See also - suffix()¶
- Return type:
- str 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns the suffix (extension) of the file. - The suffix consists of all characters in the file after (but not including) the last ‘.’. - Example: - fi = QFileInfo("/tmp/archive.tar.gz") ext = fi.suffix() # ext = "gz" - The suffix of a file is computed equally on all platforms, independent of file naming conventions (e.g., “.bashrc” on Unix has an empty base name, and the suffix is “bashrc”). - Swaps this file info with - other. This operation is very fast and never fails.- symLinkTarget()¶
- Return type:
- str 
 
 - Returns the absolute path to the file or directory a symbolic link points to, or an empty string if the object isn’t a symbolic link. - This name may not represent an existing file; it is only a string. - Note - exists()returns- trueif the symlink points to an existing target, otherwise it returns- false.- See also