Welcome! Please see the About page for a little more info on how this works.

+1 vote
in ClojureCLR by
retagged by

The ClojureCLR version of io/as-file returns a FileInfo object, which can only represent a file (and not a directory as those are represented by the DirectoryInfo class). JVM CLojure OTOH returns a File object, which can represent both. This leads to different outcomes in evaluation:

Clojure

user=> (require '[clojure.java.io :as io])
nil
user=> (.exists (io/as-file "/"))
true

ClojureCLR

user=> (require '[clojure.clr.io :as io])
nil
user=> (.Exists (io/as-file "/"))
false

Suggested fix would be to return a FileSystemInfo object, which is the parent class of both FileInfo and DirectoryInfo, and as such is capable of representing both, similar to the Java File class.

1 Answer

0 votes
by
by
The suggested fix does not really work.  `FileSystemObject` is an abstract class.  One is going to have to create either `FileInfo` or  a `DirectoryInfo` object -- you pick the one that has the functionality you need.   For this purpose, I left 'as-file` as-is and added `as-dir`.

In addition, as a rough approximation to  `clojure.java.io/file`, I added `file-info` and `dir-info`.  They will take multiple arguments, stringify them, and join them with the directory separator char interposed.  It will convert any 'wrong'  separator chars to the correct one for the platform -- once you enter the land of `DirectoryInfo` and `FileInfo`, it is hard to remain agnostic.  Thus you could do something mixed mode like `(file-info "a/b" "c\\d")`.

This will be in the alpha6 of 1.12.0 when it comes out, probably later this week.
...