I wrote these a while ago, and I'm not sure if they're still useful or not,
but I'll just send them along without any guarantee. I have used them like
(__FILE__) and (__DIR__) when I wanted to get access to things relative to
the current file.
(defmacro __FILE__ []
`(if *file*
(let [f# (ClassLoader/getSystemResource *file*)]
(if f#
(.getCanonicalPath (java.io.File. (.toURI f#)))
(.getCanonicalPath (java.io.File. *file*))))))
(defmacro __DIR__ []
`(dirname (__FILE__)))
(defn dirname [path]
(.getParent (File. path)))
Paul
On Wed, Mar 11, 2009 at 7:25 PM, Phil Hagelberg <[email protected]> wrote:
>
>
> I'm interested in getting the location on disk of the current file. It
> appears *file* provides this, but unfortunately it doesn't provide an
> absolute path.
>
> Inside the file /home/phil/src/mire/src/mire/rooms.clj:
>
> mire/rooms.clj
>
> I tried using java.io.File so I'd have access to getAbsolutePath, but
> this is inaccurate:
>
> (.getAbsoluteFile (java.io.File. *file*)) =>
> /home/phil/src/mire/mire/rooms.clj
>
> There should be a "src" directory in between "mire" and "mire".
>
> It looks like the value of *file* is relative to the classpath entry
> where the file was loaded from, but getAbsoluteFile is assuming it's
> relative to the current directory.
>
> How do you get the absolute path for the current file?
>
> -Phil
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---