I have in QGIS layer that contains filepath (e.g.
D:/file/28238/pic/D4D3-06_1.png) and I would like to get directory path only like
Is it possible to do by expression in field calculator?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
There is no builtin function in QGIS field calculator that can do your task, but luckily you can create custom function in QGIS using Function Editor in field calculator, please follow the steps below
Repalce the existing code with code shown below
from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def splitLast(splitStr,splitVal,feature,parent): return splitVal.join(splitStr.split(splitVal)[0:-1])
click the load button and restart your QGIS now again open the field calculator and you will be able to see your splitLast function in custom list as shown in figure below
Now add the following expression in expression tab and click ok and you are done.
Note:Here "rqewr" is the name of field in which "D:/file/28238/pic/D4D3-06_1.png" is stored you can also pass this string instead of field name to function.
While waiting I have done it using python:
import os path=os.path.dirname ("[% "FILEPATH" %]") os.startfile (path)
Maybe someone will use it... Thanks for your help!