from qgis.PyQt.QtCore import QUrl file_path = "/path/to/local/file.tif" url = QUrl.fromLocalFile(file_path) iface.addRasterLayer(url.toString(), "Layer Name")
from qgis.PyQt.QtCore import QUrl, QFile src_file_path = "/path/to/src/file.tif" dst_file_path = "/path/to/dst/file.tif" src_url = QUrl.fromLocalFile(src_file_path) dst_url = QUrl.fromLocalFile(dst_file_path) src_file = QFile(src_url.toLocalFile()) dst_file = QFile(dst_url.toLocalFile()) if src_file.exists(): if dst_file.exists(): dst_file.remove() src_file.copy(dst_file.fileName())In this example, we want to copy a local file from `src_file_path` to `dst_file_path`. We first create QUrl objects for both the source and destination file paths using the `QUrl.fromLocalFile()` function. We then create QFile objects for both the source and destination files using the `QFile()` constructor and passing in the local file paths obtained from the QUrl objects. Finally, we check if the source file exists using the `exists()` function, and if it does, we remove any existing destination file using the `remove()` function. We then use the `copy()` function of the source file to copy its contents to the destination file. Package library: PyQt.