daily pastebin goal
77%
SHARE
TWEET

Untitled

a guest Sep 20th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns find-m-files
  2.   (:import java.io.File))
  3.  
  4. ; Wrap java.io.file methods
  5. (defn is-file? [f] (.isFile f))
  6. (defn is-dir? [f] (.isDirectory f))
  7. (defn get-name [f] (.getName f))
  8. (defn get-path [f] (.getPath f))
  9.  
  10. (defn get-m-files [d]
  11.     "Recursively get a list of File objects for files ending in .m in the given directory"
  12.     (let [ls (if (is-dir? d) (.listFiles d) nil)
  13.           files (filter is-file? ls)
  14.           dirs (filter is-dir? ls)]
  15.       (if (nil? ls)
  16.         nil
  17.         (flatten (concat
  18.           (filter (fn [f] (re-matches #".*\.m" (get-name f))) files) ; .m files
  19.           (map get-m-files dirs))))))
  20.  
  21. (defn dupes [s]
  22.   "Get a list of the duplicate elements in [s]. That list may itself contain duplicates."
  23.   (cond
  24.     (empty? s) nil ; Break recursion
  25.     (> (.indexOf (rest s) (first s)) -1) (cons (first s) (dupes (rest s)))
  26.     true (recur (rest s))))
  27.  
  28. (defn duplicate-filenames [d]
  29.   "Get a list of the paths to all filenames that are duplicated in the given directory."
  30.   (let [files (get-m-files (File. d))
  31.         names (map get-name files)
  32.         duped-names (set (dupes names))
  33.         duped-files (filter (fn [f] (contains? duped-names (get-name f))) files)]
  34.     (map get-path
  35.       (sort #(compare (get-name %1) (get-name %2)) duped-files))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top