I am trying to iterate over a list of files in a given directory and add an extra variable i = {1,2,3 .....} to their names.
Here is the code that I have for iterating over files and changing the name of each file:
(defn addCounterToExtIn [d]
(def i 0)
(doseq [f (.listFiles (file d)) ] ; make a sequence of all files in d
(if (and (not (.isDirectory f)) ; if file is not a directry and
(= '(\. \i \n) (take-last 3 (.getName f))) ) ; if it ends with .in
(fs/rename f (str d '/ i (.getName f)))))) ; add i to start of its name
I do not know how I can increase i, as doseqiterates through each file. Alternatively, is there a better cycle to achieve the desired result?
source
share