3

I'm looking to be able to auto populate an attribute field with the project file name either by a virtual field or default option in the properties. The "@project_filename" expression always produces a result with the file extension. eg "newproject.qgs" I don't want the ".qgs" displayed.

  • 3
    just trim the last four character.... – J.R Oct 10 at 11:25
  • 4
    If you use QGIS 3, there is the @project_basename which just returns the name without path or extension. – Joseph Oct 10 at 11:27
  • Sadly at the moment I have to use 2.14 or 2.18. (office politics) The field has to populate a large number of entries automatically so manually removing the extension isn't an option. – webg Oct 10 at 13:11
6

You could replace '.qgs' by nothing '' in your expression:

replace( @project_filename , '.qgs', '')

As J.R pointed out, you could also select the whole filename, minus the last 4 characters

substr( @project_filename ,1,-4)
  • replace( @project_filename , '.qgs', '') That does the trick thanks. – webg Oct 10 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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