Function: dired-do-create-files-regexp

dired-do-create-files-regexp is an autoloaded and byte-compiled function defined in dired-aux.el.gz.

Signature

(dired-do-create-files-regexp FILE-CREATOR OPERATION ARG REGEXP NEWNAME &optional WHOLE-NAME MARKER-CHAR)

Source Code

;; Defined in /usr/src/emacs/lisp/dired-aux.el.gz
(defun dired-do-create-files-regexp
    (file-creator operation arg regexp newname &optional whole-name marker-char)
  ;; Create a new file for each marked file using regexps.
  ;; FILE-CREATOR and OPERATION as in dired-create-files.
  ;; ARG as in dired-get-marked-files.
  ;; Matches each marked file against REGEXP and constructs the new
  ;;   filename from NEWNAME (like in function replace-match).
  ;; Optional arg WHOLE-NAME means match/replace the whole file name
  ;;   instead of only the non-directory part of the file.
  ;; Optional arg MARKER-CHAR as in dired-create-files.
  (let* ((fn-list (dired-get-marked-files nil arg))
	 (operation-prompt (concat operation " `%s' to `%s'?"))
         (rename-regexp-help-form (format-message
                                   (substitute-command-keys "\
Type \\`SPC' or \\`y' to %s one match, \\`DEL' or \\`n' to skip to next,
\\`!' to %s all remaining matches with no more questions.")
                                   (downcase operation)
                                   (downcase operation)))
	 (regexp-name-constructor
	  ;; Function to construct new filename using REGEXP and NEWNAME:
	  (if whole-name		; easy (but rare) case
	      (lambda (from)
		(let ((to (dired-string-replace-match regexp from newname))
		      ;; must bind help-form directly around call to
		      ;; dired-query
		      (help-form rename-regexp-help-form))
		  (if to
		      (and (dired-query 'rename-regexp-query
					operation-prompt
					from
					to)
			   to)
		    (dired-log "%s: %s did not match regexp %s\n"
			       operation from regexp))))
	    ;; not whole-name, replace non-directory part only
	    (lambda (from)
	      (let* ((new (dired-string-replace-match
			   regexp (file-name-nondirectory from) newname))
		     (to (and new	; nil means there was no match
			      (expand-file-name new
						(file-name-directory from))))
		     (help-form rename-regexp-help-form))
		(if to
		    (and (dired-query 'rename-regexp-query
				      operation-prompt
				      (dired-make-relative from)
				      (dired-make-relative to))
			 to)
		  (dired-log "%s: %s did not match regexp %s\n"
			     operation (file-name-nondirectory from) regexp))))))
	 rename-regexp-query)
    (dired-create-files
     file-creator operation fn-list regexp-name-constructor marker-char)))