comparison src/clojureDemo/sys_utils.clj @ 1:6d9bdaf919f7

added clojureDemo source
author Robert McIntyre <rlm@mit.edu>
date Fri, 20 Aug 2010 00:32:44 -0400
parents
children
comparison
equal deleted inserted replaced
0:163bf9b2fd13 1:6d9bdaf919f7
1
2 (ns clojureDemo.sys-utils
3
4 (:use [clojure.contrib duck-streams str-utils shell-out])
5 (:import java.io.File)
6 )
7
8
9
10 (defn rename [file]
11
12 (if (re-matches #".*\.JPG$" (str file))
13 (sh "mv" (str file) (re-sub #"\.JPG" ".jpg" (str file)))
14 nil))
15
16
17
18
19 (defn escape-spaces
20 [string]
21 (re-gsub #" " (str \-) string))
22
23
24 (defn view
25 [string]
26 (seq (char-array string)))
27
28 (defn parent-source [target file]
29 (File. (str target "/" (.getName (.getParentFile file))"-" (.getName file))))
30
31
32 (defn rsync [file1 file2]
33 (let [*out* nil]
34 (sh "rsync" "-avz" (str file1) (escape-spaces(str file2)))))
35
36 (defn shunt-file [target file]
37 (rsync (str file) (str (parent-source target file))))
38
39
40
41 (defn extract-files
42 [regex source destination]
43
44 (dorun (map (partial shunt-file destination)
45 (filter (comp not nil? (partial re-matches regex) str) (file-seq source)))))
46
47
48 (defn file-count [#^java.io.File file]
49 (count (file-seq file)))
50
51
52
53
54 (comment
55
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/"))))
61
62
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/"))))
68
69 )