6

I would like to change the default path for saving layers ("Save as" in the main layers panel). Now the default is C:\Program Files\QGIS Lyon\bin (in which I even don't have the rights to save apparently...).

Many answers on this forum tell that it should not be like this, and that QGIS will save in the last folder used. This is not the case in my situation.

I even saved the whole QGIS project in the by me desired folder. Every single shp file I want to save, is by directed to the QGIS Lyon\bin folder by default; unless I first click the "browse"-button, then it goes to the desired folder; If I don't first click the "browse"-button, it directs to the bin folder.

5
  • Maybe you need the write access to that folder to change the path. I only get that preset if the last used folder is removed in the meantime.
    – AndreJ
    Commented Mar 8, 2016 at 7:11
  • You mean that after I have access to the C:\Program Files\QGIS Lyon\bin it will remember the last location of saving?
    – Rob
    Commented Mar 8, 2016 at 9:14
  • It is worth a try. I always grant myself full rights on my own computers, and seldomly get the bin path as preset.
    – AndreJ
    Commented Mar 8, 2016 at 17:49
  • Was there a solution for this, I have the same problem (folder C:\Windows\System32) unless I choose browse Commented Jan 31, 2022 at 9:20
  • Anything new? With my Windows installation, QGIS saves by default to ...\documents\ Also it would be nice to have the option of a default path for each project!
    – S.E.
    Commented May 27, 2022 at 16:09

1 Answer 1

4

On my Windows 10 install of QGIS 3.10 the default folder is set in the properties of the shortcut used to start QGIS (on my system the shortcut is located in the following folder C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs).

As a word of caution several shortcuts are created on a Windows install - make sure you change the one you use to start QGIS.

Right clicking on the Shortcut and choosing properties from the menu allows me to see and change the 'Start in:' folder location, which changes where my QGIS session saves newly created layers by default:

QGIS3 shortcut

shortcut change

So if I fire up QGIS using the shortcut and create a new point shp file, I can type the name directly into the 'File name' box without clicking the dots:

create

...and when I click OK my 'test' shp file is saved to the folder set by the 'Start in' location of the shortcut:

output

Changing where shp files are saved to match a project home folder is possible, but not absolutely seamless as QGIS uses the default folder set by the shortcut used to start it until you click the dots in the New Shapefile Layer dialogue box.

Once you click those dots QGIS reads the settings from 'lastVectorFileFilterDir' in the settings file QGIS3.ini. You can use this behaviour to write settings to that file that change where several of QGIS's dialogues boxes look.

Open up the project you want to work with and run the following code in the Python console:

import os
from qgis.core import QgsProject
from PyQt5.QtCore import QSettings
prjhomepath = QgsProject.instance().homePath()
if os.path.exists(prjhomepath):
   QSettings().setValue('/UI/lastVectorFileFilterDir',prjhomepath)

python console

The code sets the variable 'prjhomepath' to the projects home folder, checks to see if it exists, if it does then it changes the lastVectorFileFilterDir folder setting to match. To check it's worked go to create a new shp file, click on the dots:

create shp file

and the dialogue should open in the project home folder. Clicking on the dots is crucial though - until you do that QGIS uses the path set by the shortcut used to start it.

Clicking the dots makes QGIS read the QGIS3.ini file to get the folder location. The good news is you only need to do it once after you've run the code.

To try and automate the folder change you could wrap the code in a macro, that runs each time you open your project. You might have to tweak your Settings->Options to allow the macro to run

macro settings

macros

As you can see from the code I'm changing a few default folder settings!

Rather than having to mess around with code/macros it would be great to have a QGIS project setting that allowed you to tick a box to use the home folder as the default file location. It would also be good if QGIS used the folder settings in QGIS3.ini on start up rather than on dialogue initiation which seems to currently be the case.

Hope the above helps!

1
  • This is no longer required. I am using 3.22.14, but I don't know when the default save location was changed.
    – Foggy
    Commented Mar 9, 2023 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.