[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to rename files to numbers in Eshell?
From: |
Jean Louis |
Subject: |
Re: How to rename files to numbers in Eshell? |
Date: |
Sat, 11 Sep 2021 16:40:28 +0300 |
User-agent: |
Mutt/2.0.7+183 (3d24855) (2021-05-28) |
* Felix E. Klee <felix.klee@inka.de> [2021-09-11 16:16]:
> Consider a list of files:
>
> $ ls -1 *.jpg
> IMG_20210909_0003.jpg
> IMG_20210909_0004.jpg
> IMG_20210909_0005.jpg
> IMG_20210909_0006.jpg
> IMG_20210909_0007.jpg
> …
>
> I want to rename these files to `1.jpg`, `2.jpg`, …, and I know how to
> do it with Dired. However, this time I want to do it with Eshell.
>
> My own attempt, works, but I think there should be an easier way:
>
> $ listify *.jpg
> $ setq my-files $$
> $ setq my-numbers $(number-sequence 1 (length my-files))
> $ setq my-pairs $(mapcar* 'cons my-files my-numbers)
> $ for pair in $my-pairs { setq a (car pair); setq b (cdr pair);
> mv $a "$b".jpg }
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 *
I have chosen to renumber it by date, you can customize it
yourself. It is handy when I am downloading many pictures or videos,
then I know at what date they were downloaded. Of course in that case
I don't mind of file names significance, that is why I am renumbering
them.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
- How to rename files to numbers in Eshell?, Felix E. Klee, 2021/09/11
- Re: How to rename files to numbers in Eshell?,
Jean Louis <=
- Re: How to rename files to numbers in Eshell?, Felix E. Klee, 2021/09/12
- Re: How to rename files to numbers in Eshell?, Jean Louis, 2021/09/12
- Re: How to rename files to numbers in Eshell?, Jean Louis, 2021/09/13
- Re: How to rename files to numbers in Eshell?, tomas, 2021/09/13
- Re: How to rename files to numbers in Eshell?, Felix E. Klee, 2021/09/14
- Re: How to rename files to numbers in Eshell?, Jean Louis, 2021/09/14
- Re: How to rename files to numbers in Eshell?, tomas, 2021/09/14
- Re: How to rename files to numbers in Eshell?, Felix E. Klee, 2021/09/14
- Re: How to rename files to numbers in Eshell?, Jean Louis, 2021/09/14
- Re: How to rename files to numbers in Eshell?, Felix E. Klee, 2021/09/14