How to sequentially number files in a folder

Moderator: Forum moderators

Post Reply
User avatar
Flash
Moderator
Posts: 981
Joined: Tue Dec 03, 2019 3:13 pm
Location: Arizona, U.S.
Has thanked: 52 times
Been thanked: 127 times

How to sequentially number files in a folder

Post by Flash »

Note: this thread was split from another thread where it was off-topic. The first few posts might be confusing. Press on regardless. :)

Thanks for that, MochiMoppel. I use Rox's bulk rename to renumber the files in audiobooks. I'll have to see if the drag and drop feature works with it.

Chaos coordinator :?
User avatar
MochiMoppel
Posts: 1243
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 444 times

Re: How to sequentially number files in a folder?

Post by MochiMoppel »

Flash wrote: Thu Aug 04, 2022 2:47 am

I use Rox's bulk rename to renumber the files in audiobooks. I'll have to see if the drag and drop feature works with it.

And? Does it work? I guess not.
But I'm curious to know how you can renumber files with Rox's bulk rename. Example please.

User avatar
Flash
Moderator
Posts: 981
Joined: Tue Dec 03, 2019 3:13 pm
Location: Arizona, U.S.
Has thanked: 52 times
Been thanked: 127 times

Re: How to sequentially number files in a folder?

Post by Flash »

MochiMoppel wrote: Wed Aug 10, 2022 8:16 am
Flash wrote: Thu Aug 04, 2022 2:47 am

I use Rox's bulk rename to renumber the files in audiobooks. I'll have to see if the drag and drop feature works with it.

And? Does it work? I guess not.
But I'm curious to know how you can renumber files with Rox's bulk rename. Example please.

I haven't had an opportunity to use the drag and drop feature yet.
As for bulk renumbering files,

Rox bulk renumber.jpg
Rox bulk renumber.jpg (47.99 KiB) Viewed 1697 times

To start with, the files are already numbered 001.jpg, 002.jpg, etc. I use Rox's bulk rename first to remove the leading zero (if not needed,) then again to add "of 67" to each file name.

Many years ago someone in the forum (moose? Something like that I think) made this script to use for renumbering audio books after ripping them with pcdripper:

Code: Select all

#!/bin/bash

sourcefolder=`pwd`

c=1
ls "$sourcefolder" | while read a;do

  b=`echo "00$c" | sed "s/.*\(...\)$/\1/"`
  echo "$b.mp3"

  mv "$sourcefolder/$a" "$sourcefolder/$b.mp3"

  c=$(($c+1))
done

Be careful, if you save it as a file in Rox and then click on it, it will rename all the files and folders in the directory where you put it. Ask me how I know. :oops: Best to put it in its own directory, to limit the damage it can do.

Chaos coordinator :?
User avatar
MochiMoppel
Posts: 1243
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 444 times

How to sequentially number files in a folder?

Post by MochiMoppel »

Flash wrote: Wed Aug 10, 2022 5:38 pm

Best to put it in its own directory, to limit the damage it can do.

:shock: Best to put it into your trash can! It's toxic and can ruin your system. Was proposed to you by forum member MU in your thread How to batch renumber files in a folder?, Originally was OK, then seaside proposed a dangerous change. Now if you run the script from a console and forget to open the console in the working directory it will rename all your files and directories in /root :o Certainly the last thing anyone would want.

Your original question back then was
"Is there a Regular Expression I can put in ROX's Bulk rename window that will rename the files in this folder, starting with 001 for the first file (now 0101) and ending at 231 for the last file (now 1220)?"
and the answer was no. You can not renumber filenames with ROX's Bulk rename window (hence the funny numbering script). Your post-processing with ROX is in my understanding formatting or string manipulation but not numbering.

If I understand correctly you still use the script, then ROX to do the rest. IMHO it would be much easier (and safer) to do all this at once, using a dedicated renaming tool like gFnRename or @JakeSFR 's MultiRename.

Screenshot.png
Screenshot.png (53.77 KiB) Viewed 1807 times
multirename.png
multirename.png (121.55 KiB) Viewed 1807 times
geo_c
Posts: 2883
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 2208 times
Been thanked: 880 times

Re: How to sequentially number files in a folder?

Post by geo_c »

MochiMoppel wrote: Thu Aug 11, 2022 5:35 am

IMHO it would be much easier (and safer) to do all this at once, using a dedicated renaming tool like gFnRename or @JakeSFR 's MultiRename.

I was using MultiRename last night to number .wav files so a script could create a soundfont. MultiRename is a great tool!

geo_c
Old School Hipster, and Such

User avatar
Flash
Moderator
Posts: 981
Joined: Tue Dec 03, 2019 3:13 pm
Location: Arizona, U.S.
Has thanked: 52 times
Been thanked: 127 times

Re: ROX: How to make the "Rename" box wider

Post by Flash »

@MochiMoppel, pardon my slow response.

You are correct, I misspoke in saying I used Rox to renumber.

Thanks for the examples of how to use the renaming utilities. I had looked at one of them years ago but couldn't see how to use it to do what I wanted. Since what I was using worked well enough, I didn't bother with them any further. Now with some examples to start with, I'll give gFnRename a try next time I need to renumber the files of an audio book.

Incidentally, gFnRename comes with EasyOS, in the Filesystem section of the Menu. Since it calls itself a utility, I initially looked for it in the Utility section of the Menu. It took me a while to find it.

Chaos coordinator :?
bob93
Posts: 53
Joined: Fri Nov 25, 2022 8:29 am
Location: Fossapup64 9.5
Has thanked: 21 times
Been thanked: 1 time

Re: How to sequentially number files in a folder

Post by bob93 »

Hey there
Does anyone know of a way to "randomize" filenames by using a random sequence of numbers or characters in the name of each file? I have Multirename and don't see a way to do this. Perhaps it supports regular expressions?

Fossapup64 9.5

User avatar
Trapster
Posts: 184
Joined: Sat Aug 01, 2020 7:44 pm
Has thanked: 1 time
Been thanked: 55 times

Re: How to sequentially number files in a folder

Post by Trapster »

I just used this for an .mp3 player that did not have a shuffle option.
Note - This is for .mp3 files

Copy this text into a blank file, put it in your executable path and make it executable. I named it mp3shuffle.
Open a terminal in the folder you want changed and run mp3shuffle
I presume you can change the "*.mp3" to any file suffix in the script but I have not tried that.

Code: Select all

#!/bin/bash

shopt -s extglob

rename() {
	SRC="${MAPFILE[n]}"
	DST="${PREFIX[i]}-${MAPFILE[n]#+([0-9])-}"
	[[ "$SRC" != "$DST" ]] && mv "$SRC" "$DST"
}

cd "$1" || exit

mapfile -t < <(find -maxdepth 1 -type f -iname "*.mp3" -printf "%f\n")
N=${#MAPFILE[@]}

PREFIX=($(seq -w $N))
for ((n = 0; n < N - 1; n++)); do
	i=$((n + $RANDOM % (N - n)))
	rename
	PREFIX[i]=${PREFIX[n]}
done
i=$n
[[ i -gt 0 ]] && rename
User avatar
MochiMoppel
Posts: 1243
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 444 times

Re: How to sequentially number files in a folder

Post by MochiMoppel »

bob93 wrote: Thu Jul 25, 2024 11:36 pm

Does anyone know of a way to "randomize" filenames by using a random sequence of numbers or characters in the name of each file? I have Multirename and don't see a way to do this. Perhaps it supports regular expressions?

No need for regex. You can do this with ROX-Filer
Assume a file list like this:
file_01.txt
file_02.txt
file_03.txt
file_04.txt
file_05.txt

In order to prepend these files with a random 4 digit hex number and an underbar
1) Open a ROX-Filer window and select these files
2) Press Shift + ! to open the Shell box
3) Into the box paste for f in "$@" ;do mv "$f" $(printf %04x $RANDOM)_"$f" ;done and press Enter
The file list will now look like this:
0ca9_file_03.txt
2bcc_file_02.txt
2ede_file_01.txt
3951_file_04.txt
77db_file_05.txt

Please note that the Shell box will close after execution of a command, but you can reopen it with Shift + ! and recall your last command(s) by pressing the Up button.

To remove the randomized filenames and restore the original names you could also use ROX:

rox_bulk_rename.png
rox_bulk_rename.png (22.57 KiB) Viewed 644 times
Post Reply

Return to “File Management”