Skip to content

Commit

Permalink
add copy-directory/files*
Browse files Browse the repository at this point in the history
  • Loading branch information
bennn committed May 6, 2018
1 parent 9a67494 commit 608c693
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 15 additions & 1 deletion main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down
7 changes: 6 additions & 1 deletion scribblings/gtp-util.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -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))].

Expand Down

0 comments on commit 608c693

Please sign in to comment.