From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Thorpe Newsgroups: gmane.emacs.help Subject: Re: Changing file names with "--" to "-" Date: Mon, 22 Feb 2021 04:42:41 +0000 Message-ID: <87eeh8hfwe.fsf@robertthorpeconsulting.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24953"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: wael-zwaiter@gmx.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 22 05:44:19 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lE350-0006Lv-AV for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 22 Feb 2021 05:44:18 +0100 Original-Received: from localhost ([::1]:35622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lE34z-0005tW-Av for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 21 Feb 2021 23:44:17 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lE345-0005rq-Lo for help-gnu-emacs@gnu.org; Sun, 21 Feb 2021 23:43:22 -0500 Original-Received: from outbound-smtp20.blacknight.com ([46.22.139.247]:42581) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lE342-0007WS-Vu for help-gnu-emacs@gnu.org; Sun, 21 Feb 2021 23:43:21 -0500 Original-Received: from mail.blacknight.com (pemlinmail02.blacknight.ie [81.17.254.11]) by outbound-smtp20.blacknight.com (Postfix) with ESMTPS id 6212F1C3B3D for ; Mon, 22 Feb 2021 04:43:14 +0000 (GMT) Original-Received: (qmail 16098 invoked from network); 22 Feb 2021 04:43:14 -0000 Original-Received: from unknown (HELO rt-inspiron-3480) (rt@robertthorpeconsulting.com@[51.37.90.145]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 22 Feb 2021 04:43:14 -0000 In-Reply-To: (wael-zwaiter@gmx.com) Received-SPF: pass client-ip=46.22.139.247; envelope-from=rt@robertthorpeconsulting.com; helo=outbound-smtp20.blacknight.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:128190 Archived-At: 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