From 608c6930810ffc4e53b18ddfedc0ef9471a4d20b Mon Sep 17 00:00:00 2001 From: Ben Greenman Date: Sun, 6 May 2018 14:37:36 -0400 Subject: [PATCH] add copy-directory/files* --- main.rkt | 16 +++++++++++++++- scribblings/gtp-util.scrbl | 7 ++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/main.rkt b/main.rkt index d3401ac..a1bd0bc 100644 --- a/main.rkt +++ b/main.rkt @@ -101,6 +101,12 @@ [path-string?] void?)] + [copy-directory/files* + (->* [(and/c path-string? directory-exists?) + (and/c path-string? directory-exists?)] + [path-string?] + void?)] + [copy-racket-file* (-> (and/c path-string? directory-exists?) (and/c path-string? directory-exists?) @@ -137,6 +143,8 @@ (only-in math/statistics mean stddev/mean) + (only-in racket/file + copy-directory/files) (only-in racket/format ~r) (only-in racket/class @@ -338,9 +346,15 @@ 1)) (define (copy-file* src dst [pattern "*.*"]) + (copy-thing copy-file src dst pattern)) + +(define (copy-directory/files* src dst [pattern "*"]) + (copy-thing copy-directory/files src dst pattern)) + +(define (copy-thing f-copy src dst pattern) (for ([src-file (in-glob (build-path src pattern))]) (define src-name (file-name-from-path src-file)) - (copy-file src-file (build-path dst src-name)))) + (f-copy src-file (build-path dst src-name)))) (define (copy-racket-file* src dst) (copy-file* src dst "*.rkt")) diff --git a/scribblings/gtp-util.scrbl b/scribblings/gtp-util.scrbl index b1ff43f..3c9cb89 100644 --- a/scribblings/gtp-util.scrbl +++ b/scribblings/gtp-util.scrbl @@ -171,14 +171,19 @@ If you think one of these functions should "graduate" to another library @racket{0} digits. } -@defproc[(copy-file* [src directory-exists?] [dst directory-exists?] [pattern string? "*"]) void?]{ +@defproc[(copy-file* [src directory-exists?] [dst directory-exists?] [pattern string? "*.*"]) void?]{ Copy every file from the directory @racket[src] whose name matches the given @racket[glob] pattern into the directory @racket[dst]. + Raises an exception if @racket[src] contains a directory that matches the given pattern. } @defproc[(copy-racket-file* [src directory-exists?] [dst directory-exists?]) void?]{ Same as @racket[(copy-file* src dst "*.rkt")]. } +@defproc[(copy-directory/files* [src directory-exists?] [dst directory-exists?] [pattern string? "*"]) void?]{ + Copy every file and recursively copy every directory in @racket[src] whose name matches the given pattern into the directory @racket[dst]. +} + @defproc[(enumerate [x* (listof any/c)]) (listof (cons/c natural? any/c))]{ Given a list of values @racket['(A B C)] return a list with each value indexed by its position @racket['((0 . A) (1 . B) (2 . C))].