;; perl: ;; ($op = shift) || die "Usage: rename perlexpr [filenames]\n"; ;; if (!@ARGV) { ;; @ARGV = ; ;; chop(@ARGV); ;; } ;; for (@ARGV) { ;; $was = $_; ;; eval $op; ;; die $@ if $@; ;; rename($was,$_) unless $was eq $_; ;; } (use gauche.regexp) (define (usage) (print "Usage: rename.scm REGEX FILES...") (exit)) (define (main args) (let-optionals* (cdr args) ((from #f) (to #f) . files) (when (or (not from) (not to) (null? files)) (usage)) ;;(print "from : " (regexp-quote from)) ;;(print "to : " to) ;;(print "files: " files) (let1 from (regexp-quote from) (dolist (file files) (print (list 'rename 'from from 'to to 'in file '-> (regexp-replace-all from file to))) ;; XXX file.util::move-file provides sophisticated support ;; - only do regexp-replace-all in filename part if a ;; directory part is present in the file name. ;; - really rename using sys-rename )) (print "bye.")))