You can use
org-link-set-parameters to define your own link types as demonstrated in the following Elisp snippet.
The snippet contains a function
my-org-open-file which opens the file given as org file link target.
If the file name is relative and if the file with that name does not exist
my-org-open-file tries to find an existing file by expanding the file name successively with all entries of the path list
Note that you can customize
my-org-path. Just call M-x
my-org-path RET and insert the paths you need.
my-org-open-file does not find the file at all a buffer is generated with the original file name as
(defcustom my-org-path nil
"List of paths to try with `my-org-open-file'.
If the LINK argument for `my-org-open-file' is a relative path
and a file with that path does not exist
try successively each of the directory entries of this list
as `default-directory' for expanding the path.
The directory entries can be given relative or absolute."
:type '(repeat directory)
(defun my-org-open-file (link)
"Open LINK with `org-open-file'.
If LINK is given as relative file path also try to find file
with prefixes from `my-org-path'."
(let* ((el (car (org-element-parse-secondary-string (format "[[file:%s]]" link) '(link))))
(option (org-element-property :search-option el))
(path (org-element-property :path el))
(app (org-element-property :application el))
(org-path (org-property-or-variable-value 'my-org-path t)))
(when (stringp org-path)
(setq org-path (list org-path)))
(setq path (substitute-in-file-name path))
(unless (file-name-absolute-p path)
(cl-dolist (path-prefix org-path)
(let ((try-path (expand-file-name path path-prefix)))
(when (file-exists-p try-path)
(setq path try-path)
(cond ((equal app "emacs") 'emacs)
((equal app "sys") 'system))
(cond ((not option) nil)
((string-match-p "\\`[0-9]+\\'" option)
(list (string-to-number option)))
(t (list nil option))))))
You can set the search path also in the properties drawer of an Org section as demonstrated in the following example:
* My Section
:org-search-path: ("~/tmp" "/tmp" "/temp")