Find the path to the current file

Is there a way to get the path that the current file is at? I get this won’t be possible in general, but just for setting up paths to test data in a project subdirectory; something like Node’s __dirname or Python’s __file__.

While you are loading the code (i.e., inside term expansion) you can use prolog_load_context/2 for that. That originates from Quintus and is a little portable. If you want it after loading, you have two options: use the above to register something or use source_file/2 to find the file implementing some predicate that is defined in the file.

1 Like

If your source is a module, I think you can use module_property(your_module,file(File)).

1 Like