# Simply adding a new file search path

**URL:** <https://swi-prolog.discourse.group/t/simply-adding-a-new-file-search-path/2373>\
**Category:** Help!\
**Created:** [May 19, 2020, 8:50pm UTC](https://swi-prolog.discourse.group/t/simply-adding-a-new-file-search-path/2373 "2020-05-19T20:50:05Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 20, 2020, 7:42am UTC](https://swi-prolog.discourse.group/t/simply-adding-a-new-file-search-path/2373/2 "2020-05-20T07:42:24Z")

</div>

The idea is rather simple. Files may be specified as Alias(Relative). The typical example is library(lists). The Alias is `library`, the relative path `lists`. The aliases are defined using `user:file_search_path(Alias, Dir)`. This should return candidate directories to search for files with the alias _Alias_. _Dir_ is either a concrete directory or another Alias(Relative) term.

`app_data` is not for your program. These (and a couple more) provide search paths to find application data, etc. according to the XDG desktop file organization standards.

To make a relocatable application `myapp`, it is common practice to have the main file setup a file search rule for `myapp`, pointing at the root directory of the application. You can than find all files as myapp(Relative). You typically use either prolog\_load\_context/2 to initialise the myapp alias or source\_file/2 using a unique predicate in the initial load file:

```prolog
myapp_version(1.0).

user:file_search_path(myapp, Dir) :-
     source_file(myapp_version(_), File),
     file_directory_name(File, Dir).

```

[I like these doc links! thanks @EricGT!

---

_[View the full topic](https://swi-prolog.discourse.group/t/simply-adding-a-new-file-search-path/2373)._
