It looks like you're new here. If you want to get involved, click one of these buttons!
I think what you are looking for is File.dirname:
File.dirname("/home/matthias/somefile.txt") -> "/home/matthias"
I think you mixed up "Expressions" with Ruby. "Expressions" are NOT Ruby. They are not scripts. Expressions are a low-level feature used inside KLayout for quick evaluation of numerical or conditional expressions. When you write scripts, you have to use Ruby features.