I have moved all my QGIS layer files from C:// drive to One Drive, and I would like to re-map the old filepaths to the new drive.
I know I can open the QGIS file as a text file and run a find and replace on the old filepath, so that works. But I would like to know how to do this in the Python console within the QGIS project.
I've tried lots of variations of the code below, but the layers just won't update. What am I missing?
def my_processor(path):
return path.replace('../../../../GIS - GIS Data - GIS Data', 'D:/OneDrive - CM/GIS - GIS Data/')
QgsPathResolver.setPathPreprocessor(my_processor)
ctrl+h
(search & replace) to repair the faulty paths. If your project is saved to.qgz
, you need to unzip the file first.