Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Clojure: Create a Directory

DZone's Guide to

Clojure: Create a Directory

· Java Zone
Free Resource

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

I spent much longer than I should have done trying to work out how to create a directory in Clojure as part of an import script I’m working out so for my future self this is how you do it:

(.mkdir (java.io.File. "/path/to/dir/to/create"))

I’m creating a directory which contains today’s date so I’d want something like ‘members-2014-05-24′ if I was running it today. The clj-time library is very good for working with dates.

To create a folder containing today’s date this is what we’d have:

(ns neo4j-meetup.core
  (:require [clj-time.format :as f]))
 
(def format-as-year-month-day (f/formatter "yyyy-MM-dd"))
 
(defn create-directory-for-today []
  (let [date (f/unparse format-as-year-month-day (t/now))]
    (.mkdir (java.io.File. (str "data/members-" date)))))

Initial code shamelessly stolen from Shu Wang’s gist so thanks to him as well!

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

Published at DZone with permission of Mark Needham, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}