all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: bug-gnu-emacs@gnu.org
Subject: bug#6823: 24.0.50; Wdired or Dired enhancement
Date: Mon, 09 Aug 2010 07:50:31 +0200	[thread overview]
Message-ID: <87pqxs5o7s.fsf@tux.homenetwork> (raw)
In-Reply-To: <C88DA2F83AA2412B90A418B52D30C68E@us.oracle.com>

Hi Drew,

"Drew Adams" <drew.adams@oracle.com> writes:

> Emacs sorely needs one or more commands that let you rename the
> marked files as a sequence (following a pattern).
>  
> See MS Windows for an example (but we could do better):
>  
> 1. You sort the file list the way you want, to put the files you want to
> act on in the right order.  Especially with libraries such as Francis
> Wright's `dired-sort-menu.el', you can sort Dired in many different
> ways.
>  
> 2. You mark the files you want to rename.  (In Windows you select them.)
>  
> 3. You invoke a rename command, and enter a pattern for the new names.
> The pattern includes an optional starting index, which is a whole
> number.  In Windows you put the index in parens, which are included in
> the file names.  Example: `new name (100)'.  The marked files are named
> `new name (100)', `new name (101)'...
>  
> Obviously, in Emacs we could provide for better patterns and
> substitutions than this.  But AFAIK today we offer nothing like this.
>
> If you have 1000 family photo files you want to rename to something like
> `2010 Summer Vacation (1000)', `2010 Summer Vacation (1001)' etc. (or
> even just `1000', `1001'...), then AFAIK the best you can do now is to
> use Wdired and perform query-replace with some fancy replacement
> expression.  We should offer something simpler for the common task of
> renaming a sequence of files.

We have have two tools to achieve this, wdired-change-to-wdired-mode,
and query-replace-regexp used with \, and \# in the replacement regexp.

,----
| E.g: (in dired)
| C-x C-q
| C-M-%
| ==> [A-Za-z0-9]*.jpg
| ==> 2010-summer-vaccation-\,(format "1%03d" \#).jpg
`----

You can use also this function:(You may have to run it two times in some
rare cases)

,----
| (defun serial-rename (dir ext name start)
|   "rename all the files of DIR matching regex EXT with the name NAME \
| starting to number START - ex: file01.jpg"
|   (interactive "Ddir: \nsExt(no dot): \nsName: \nnStart: ")
|   (find-file dir)
|   (let* ((ls-dir     (file-expand-wildcards (format "*.%s" ext) t))
|          (new-ls-dir (loop with len = (length ls-dir) 
|                         repeat len for count from start
|                         for fnum = (if (< start 10) "0%s" "%s")
|                         collect (concat dir name (format fnum count) "." ext))))
|     (loop for i in ls-dir for index from 0
|        for new-name = (nth index new-ls-dir)
|        unless (file-exists-p new-name) do (rename-file i new-name)))
|   (revert-buffer nil t nil))
`----



-- 
Thierry Volpiatto
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 






  parent reply	other threads:[~2010-08-09  5:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-07 18:37 bug#6823: 24.0.50; Wdired or Dired enhancement Drew Adams
2010-08-09  2:59 ` Eli Zaretskii
2010-08-09  6:08   ` Thierry Volpiatto
2010-08-09 14:02   ` Drew Adams
2010-08-09  5:50 ` Thierry Volpiatto [this message]
2010-08-09 14:16   ` Drew Adams
2010-08-09 14:48     ` Thierry Volpiatto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pqxs5o7s.fsf@tux.homenetwork \
    --to=thierry.volpiatto@gmail.com \
    --cc=bug-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.