Lean 4 (Meta)programming Cookbook

How to concatenate file paths🔗

To concatenate file paths, you can use the System.FilePath module. You can create a file path using System.mkFilePath and then concatenate it with another path using the / operator:

def concatPaths (base : System.FilePath) (sub : String) : System.FilePath := base / System.mkFilePath [sub] { toString := "home/user/dir" }#eval concatPaths (System.mkFilePath ["home", "user"]) "dir" { toString := "home/user/dir" }#eval System.mkFilePath ["home", "user"] / System.mkFilePath ["dir"]

This object you can use like usual since the new path is still a System.FilePath object.