Is there a way to get the path and the file name of the current project from a python script? I'm currently trying to develop a python plugin for qgis and I need to create a file with a similar name in the same folder.
You can use the following method from the QgsProject class to retrieve the path to the project file:
If there is no project loaded, or the current project has not yet been saved, this will return an empty QString:
You can convert the project file path further to a Python Unicode string (if needed) with:
However, if you intend to have your plugin be cross-platform, you are better off not working with the file path as a string in Python, but leverage Qt's excellent QFileInfo class: