Thank you Chris!
Your tip/code has partly solved my problem.
I modified call scan to make use of a negative count (using -2 instead of 4); this gets me the libpath that I need.
However, when I now use &libpath to import a text file, for example datafile= "&libpath\180106_imaging_brain\test1.tab",
then I get the error message: "File Name value exceeds maximum length of 201 characters".
I tried modifying the code (incl. changing $ 255), but without success.

Can you please recommend me what to do to import the (simple) .tab file?
using the relative path.

Thanks!