view src/clojureDemo/sys_utils.clj @ 21:e72220627685 tip

0.002 inch discrepancy with target. going to test anyway
author Robert McIntyre <rlm@mit.edu>
date Mon, 30 Aug 2010 01:19:21 -0400
parents 6d9bdaf919f7
children
line wrap: on
line source

2 (ns clojureDemo.sys-utils
4 (:use [clojure.contrib duck-streams str-utils shell-out])
5 (:import java.io.File)
6 )
10 (defn rename [file]
12 (if (re-matches #".*\.JPG$" (str file))
13 (sh "mv" (str file) (re-sub #"\.JPG" ".jpg" (str file)))
14 nil))
19 (defn escape-spaces
20 [string]
21 (re-gsub #" " (str \-) string))
24 (defn view
25 [string]
26 (seq (char-array string)))
28 (defn parent-source [target file]
29 (File. (str target "/" (.getName (.getParentFile file))"-" (.getName file))))
32 (defn rsync [file1 file2]
33 (let [*out* nil]
34 (sh "rsync" "-avz" (str file1) (escape-spaces(str file2)))))
36 (defn shunt-file [target file]
37 (rsync (str file) (str (parent-source target file))))
41 (defn extract-files
42 [regex source destination]
44 (dorun (map (partial shunt-file destination)
45 (filter (comp not nil? (partial re-matches regex) str) (file-seq source)))))
48 (defn file-count [#^java.io.File file]
49 (count (file-seq file)))
54 (comment
56 (defn test-extract
57 []
58 ((partial extract-files #".*\.JPG"
59 (file-str " /home/r/Desktop/judy_yates_computer_archive/MyDocuments/dallas townhome")
60 (file-str "/home/r/Desktop/judyates_admin/archive-source-images/"))))
63 (defn judy-jpg-extract
64 []
65 ((partial extract-files #".*\.JPG"
66 (file-str "/home/r/Desktop/judy_yates_computer_archive")
67 (file-str "/home/r/Desktop/judyates_admin/archive-source-images/"))))
69 )