Subgroup: File
Class: QgsFileUtils¶
-
class
qgis.core.
QgsFileUtils
¶ Bases:
sip.wrapper
Class for file utilities.
New in version 3.0: Methods
addExtensionFromFilter
Ensures that a fileName
ends with an extension from the specifiedfilter
string.ensureFileNameHasExtension
Ensures that a fileName
ends with an extension from the provided list ofextensions
.extensionsFromFilter
Returns a list of the extensions contained within a file filter
string.representFileSize
Returns the human size from bytes stringToSafeFilename
Converts a string
to a safe filename, replacing characters which are not safe for filenames with an ‘_’ character.Signals
Attributes
-
addExtensionFromFilter
(fileName: str, filter: str) → str¶ Ensures that a
fileName
ends with an extension from the specifiedfilter
string.E.g. a
fileName
of “d:/my_file” with a filter of “GeoTIFF Files (*.tiff *.tif)” will return “d:/my_file.tif”, where asfileName
of “d:/my_file.TIFF” or “d:/my_file.TIF” will be returned unchanged.See also
See also
-
ensureFileNameHasExtension
(fileName: str, extensions: Iterable[str]) → str¶ Ensures that a
fileName
ends with an extension from the provided list ofextensions
.E.g. if extensions contains “tif” and “tiff”, then a
fileName
of “d:/my_file” will return “d:/my_file.tif”. AfileName
of “d:/my_file.TIFF” or “d:/my_file.TIF” will be returned unchanged.See also
See also
-
extensionsFromFilter
(filter: str) → List[str]¶ Returns a list of the extensions contained within a file
filter
string. E.g. afilter
of “GeoTIFF Files (*.tiff *.tif)” would return a list containing “tiff”, “tif”. The initial ‘.’ is stripped off the extension.See also
See also
-
representFileSize
(bytes: int) → str¶ Returns the human size from bytes
-
stringToSafeFilename
(string: str) → str¶ Converts a
string
to a safe filename, replacing characters which are not safe for filenames with an ‘_’ character.Warning
This method strips slashes from the filename, so it is safe to call with file names only, not complete paths.
-