[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to rename files to numbers in Eshell?
From: |
Emanuel Berg |
Subject: |
Re: How to rename files to numbers in Eshell? |
Date: |
Wed, 22 Sep 2021 16:27:46 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Jean Louis wrote:
> This may serve as starting point:
>
> (defun renumber-files (&optional files)
> "This function works within Dired or Directory Editor in GNU
> Emacs. It will rename bunch of files and renumber them
> automatically by date and number of the file. It is useful when
> you are renaming less important images or bunch of files with
> irrelevant file names."
> (interactive)
> (let* ((files (or files (dired-get-marked-files)))
> (count 1))
> (dolist (file files)
> (let* ((extension (file-name-extension file))
> (filename (format "%s-%06.f.%s" (format-time-string "%F") count
> extension)))
> (rename-file file filename)
> (setq count (+ count 1))))))
>
> Then in eshell:
>
> $ renumber-files *
That's the spirit Jean - we do _everything_ in Elisp, however
the time, place, and manner of invocation is entirely optional
and up to the user's preference and discretion.
It's interface-agnostic (or client-agnostic) computing
for YOU!
However your style has, in your phrasing, "a bunch" of
flaws ... as in formally
Second line should not have indentation
First line is not a complete sentence
Argument ‘files’ should appear (as FILES) in the doc string
The first `let*' does not have to be parallel but can be the
sequential `let'.
It also lacks a
(require 'dired)
because of `dired-get-marked-files'.
And there is no need to increment the count manually with the
error-prone out-of-baseline `setq' when you instead can have
a twin iterate/increment loop with `cl-loop' _or_ if you
insist to do it manually you still don't need setq but can use
`cl-incf' and if you insist on setq you can still use `1+'
But that's just me insisting!
Wait, let's just increment manually ...
+1
Sweet :)
--
underground experts united
https://dataswamp.org/~incal
- Re: How to rename files to numbers in Eshell?, (continued)
- Re: How to rename files to numbers in Eshell?, Michael Heerdegen, 2021/09/16
- Re: How to rename files to numbers in Eshell?, Felix E. Klee, 2021/09/17
- Re: How to rename files to numbers in Eshell?, Emanuel Berg, 2021/09/24
- Re: How to rename files to numbers in Eshell?, Jean Louis, 2021/09/25
- Re: How to rename files to numbers in Eshell?, Emanuel Berg, 2021/09/25
- Re: How to rename files to numbers in Eshell?, Emanuel Berg, 2021/09/22
Re: How to rename files to numbers in Eshell?,
Emanuel Berg <=
Re: How to rename files to numbers in Eshell?, Felix E. Klee, 2021/09/16