scheme shell
about
download
support
resources
docu
links
 
scsh.net

Delete Text Files

Loose women easily clog even large drives. (Walt D.)

 #!/usr/local/bin/scsh \
 -e main -s
 !#

;;; text file deletion for the morally robust

(define (true? x) (not (not x)))

;; Looses on file names with substring "text". (define (textfile? name) (true? (string-contains-ci (run/string (file ,name)) "text")))

;; somewhat more ambitious (define (textfile? name) (true? (regexp-search? (rx ,name ":" (* any) (w/nocase " text")) (run/string (file ,name)))))

(define (find-filenames dir) (run/strings (find ,dir -type f -print)))

(define (enforce-usage args) (or (and (= (length args) 2) (file-exists? (second args)) (file-directory? (second args))) (begin (format #t "USAGE: ~a DIRNAME --delete all text files in said dir.~%" (first args)) (exit -1))))

(define (main args) (enforce-usage args) (for-each (lambda (fn) (format #t "~a~%" fn) (delete-file fn)) (filter textfile? (find-filenames (second args)))))


DeleteTextFiles - raw wiki source | code snippets archive