all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Robert Thorpe <rt@robertthorpeconsulting.com>
To: wael-zwaiter@gmx.com
Cc: help-gnu-emacs@gnu.org
Subject: Re: Changing file names with "--" to "-"
Date: Mon, 22 Feb 2021 04:42:41 +0000	[thread overview]
Message-ID: <87eeh8hfwe.fsf@robertthorpeconsulting.com> (raw)
In-Reply-To: <trinity-cd206881-a2d4-4a2d-b47e-57feda967505-1613876784264@3c-app-mailcom-bs01> (wael-zwaiter@gmx.com)

wael-zwaiter@gmx.com writes:

> I have a lot of files and want to change "--" to "-".
>
> Am using
>
> rename 's/--/-/g' *
>
> on the current directory.
>
> How can I recursively go through all sub directories and do the
> changes for files only.

People have provided lots of good suggestions for doing this with the
shell.  You can also do this with Emacs.  I would tend to do it with
Emacs myself.

Firstly do "M-x find-name-dired".  You can type "M-x f-n-d" then press
tab.  Since Emacs has separate expansion for each word these days, that
will auto complete.

Then fill in the directory to start from.  After that it will prompt you
"Find name (file wildcard): ".  Just put in "*".  That will find all
files in the directory and every subdirectory.

Wait until find has finished (see it's mode line indicator).  Then
you'll have a dired buffer containing every file and sub-directory in
that directory.

Now, enable writeable dired with "C-x C-q".  Now you can treat the dired
buffer as a normal buffer.  Then use normal search-and-replace.  You can
use "M-%" to replace "--" with "-".  You can use query-replace or
replace all using "a".  Then if everything is ok press "C-c C-c" to make
the actual changes.  If things are wrong then press "C-c ESC".  Emacs
will then spend a while doing the renames.

The contents of the buffer will disappear at this point.  That's a
little disconcerting, but anyway, you're finished.  All of the files are
renamed.  To view them do "M-x find-name-dired" again.

This method will also rename *sub-directories* containing "--", which
might not be what you want.  Using query-replace and checking everything
is a way to avoid that.

BR,
Robert Thorpe



      parent reply	other threads:[~2021-02-22  4:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-21  3:06 Changing file names with "--" to "-" wael-zwaiter
2021-02-21  3:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-21  6:45 ` Changing file names with "--" to "-" recursively Jean Louis
2021-02-21  7:46   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-21 12:42     ` Jean Louis
2021-02-21 13:41   ` ken
2021-02-22  6:36   ` David Masterson
2021-02-22  4:42 ` Robert Thorpe [this message]

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=87eeh8hfwe.fsf@robertthorpeconsulting.com \
    --to=rt@robertthorpeconsulting.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=wael-zwaiter@gmx.com \
    /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.