Fork me on GitHub
#babashka
<
2023-09-10
>
DeepReef1113:09:04

Is there a way to get the path to the directory where the script was launched (or the project)? So that command will get the path of the project's folder no matter where it is

2
borkdude13:09:44

Please give an example because I have an ambiguous understanding of your question

DeepReef1113:09:24

Ex: Script is at /home/dir/project/script.clj I launch it from cmd while i'm in /home/dir and return /home/dir/project/. I call it from /tmp and I get /home/dir/project/

borkdude13:09:06

You can do this by using *file*:

(ns script)

(require '[babashka.fs :as fs])
(def script-file *file*)
(def script-dir (str (fs/parent script-file)))

borkdude13:09:36

you must execute this on the top level like in the above example, it does not work in function bodies, since *file* isn't bound anymore

2