Check that file exists: Difference between revisions
Content deleted Content added
m →{{header|JScript}}: change to JavaScript, works with JScript |
updated Clojure version |
||
Line 217: | Line 217: | ||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
<lang clojure> |
|||
(import '(java.io File)) |
|||
(import '(java.io File)) |
|||
(new File "/input.txt")) |
|||
(defn kind [filename] |
|||
(when (not (. file exists)) (println file "is missing")) |
|||
(let [f (File. filename)] |
|||
(when (. file isDirectory) (println file "is a directory!"))) |
|||
(cond |
|||
(.isFile f) "file" |
|||
(.isDirectory f) "directory" |
|||
(.exists f) "other" |
|||
:else "(non-existent)" ))) |
|||
(when (. file isDirectory) (println file "is a directory!")) |
|||
(defn look-for [filename] |
|||
(println filename ":" (kind filename))) |
|||
(look-for "file.txt") |
|||
(look-for "/file.txt") |
|||
(look-for "docs") |
|||
(look-for "/docs") |
|||
</lang> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |