;;; rename.el ---
;;Author:QinGW
;;(rename-file "foo" "fool")
;; Thanks Hiroyuki Komatsu(defun mell-string-split (string regexp). Some functions from his mell-string.el
"Divide STRING from REGEXP."
(let ((start 0) match-list splited-list)
(while (string-match regexp string start)
(setq match-list
(append match-list (list (match-beginning 0) (match-end 0))))
(setq start (match-end 0))
)
(setq match-list (append '(0) match-list (list (length string))))
(while match-list
(setq splited-list
(cons (substring string (nth 0 match-list) (nth 1 match-list))
splited-list))
(setq match-list (nthcdr 2 match-list))
)
(reverse splited-list)))
(defun mell-string-replace (target-string from-regexp to-string)
"Replace TARGET-STRING from FROM-REGEXP to TO-STRING."
(if (string-match from-regexp target-string)
(setq target-string
(mapconcat '(lambda (x) x)
(mell-string-split target-string from-regexp)
to-string))
)
target-string)
;;batch rename file
;;just eval C-x C-e, I don't extract them into one function.
;;it can implement to change all files of prefix with 'u' into 'U' under current ;;directory
(let
((dirfiles (directory-files "." t "^u")))
(while dirfiles
(setq filename (car dirfiles))
(setq newfilename (mell-string-replace filename "u" "U"))
(print newfilename)
(rename-file filename newfilename)
(setq dirfiles (cdr dirfiles))
))
(length (directory-files "." t "^u"))
(provide 'rename)
;;; rename.el ends here