Check that file exists: Difference between revisions

Content added Content deleted
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))
(doseq file (list (new File "input.txt")
(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
(doseq file (list (new File "docs")
(.isFile f) "file"
(new File "/docs"))
(.isDirectory f) "directory"
(when (not (. file exists)) (println file "is missing"))
(.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}}==