title: How to rename a clojure file and namespace
body: <p>I've actually got the renaming the file portion down, but now I'm trying to figure out how to rename a namespace.  The idea here is I want to iterate through a bunch of <code>.clj</code> files in a directory and rename them.  Ex:</p>
  
  <p>File: <code>some-file-123.clj</code>
  contents:</p>
  
  <pre class="lang-clj prettyprint-override"><code>(ns some-file-123
    (require [clojure.string :as str]))
  
  (defn some-func [] (println "ima func"))
  </code></pre>
  
  <p><code>-&gt;</code></p>
  
  <p>File: <code>123-some-file.clj</code>
  contents:</p>
  
  <pre class="lang-clj prettyprint-override"><code>(ns 123-some-file
    (require [clojure.string :as str]))
  
  (defn some-func [] (println "ima func"))
  </code></pre>
  
  <p>I've got all of the string manipulation stuff under control, what I'm trying to understand is how to go about reading clojure file contents, identifying the namespace, and replacing it.</p>
  
  <p>What I've come across so far involves using <code>clojure.walk</code>, for example:</p>
  
  <pre class="lang-clj prettyprint-override"><code>(let [file (first (get-some-file-fn))
        file-text (read-string (slurp file))]
      (clojure.walk/postwalk-demo file-text))
  </code></pre>
  
  <p>I know I can use <code>clojure.walk/postwalk-replace</code> to do some replacement, but I'm stuck here.</p>
  
  <p>How do I </p>
  
  <ol>
  <li>Extract the namespace from the <code>file-text</code></li>
  <li>Replace the namespace with some arbitrary new name using <code>postwalk-replace</code></li>
  <li>Is this even the right approach?</li>
  </ol>