AlomWare Toolbox Forum

General Category => Tips and Tricks => Topic started by: oblivion on December 07, 2025, 05:06:53 AM

Title: Sequential file numbering
Post by: oblivion on December 07, 2025, 05:06:53 AM
This is another (OK, niche!) podcast renaming script, at least as far as I'm concerned, but it's a little different and too complex to work in a straight text substitution style.

So some of the podcasts I get, rather than naming them by today's date, I just want them to be named sequentially. So I want to actually look at previous files, find the latest, add one to the previous number and save.

It's a bit more complicated, mostly all my own work but Paul helped me make the leading zeroes work and added a facility that saved me a few steps. So another joint effort. I use this one regularly, along with a variant for two other podcasts that are named similarly, and it saves an awful lot of manual messing around.

(Start)
TIP: Copy from Start to End to paste into an action.
0001 Keyboard: Clear trigger typing ""
0002 Computer: DOS command "dir /b /o-n "c:\podcasts\buglets*.mp3""
0003 String: Assign "dos$"
0004 String: Get line number "1"
0005 String: Assign left$ and right$ of "."
0006 String: Assign "left$"
0007 String: Get last chars "4"
0008 Counter: Assign "string$"
0009 Counter: Increase by "1"
0010 String: Assign "counter$"
0011 String: Pad start with "4,0"
0012 Clipboard: Assign text "c:\podcasts\bugletsstring$.mp3"
0013 Keyboard: Paste ""
(End)

I'll walk you through it.

First, it's invoked with a three letter acronym, so the first line removes the typed string.

Line 2 runs a dos directory command. The various parameters strip out everything but the filenames themselves and sorts them into reverse order, alphabetically. The files are all called buglets followed by a four digit number and ending in .mp3, so the file with the largest number will be listed first.

The dos$ variable holds the output of that command; line 3 makes that output the active string for the action to work with.

Line 4 -- one of Paul's additions, saved me from having to count characters, which was the first iteration of the script -- gets the first line of the output, which is the name of the file with the largest number following the base filename.

We don't care about the file's extension -- it's always mp3 -- and line 5 splits the filename into the bits left and right of the dot. We're going to work with the left side, so line 6 sets that as the active string.

The last four characters is the numeric element, so line 7 captures that bit, and line 8 sets that as the active string.

Line 9 adds 1 to the four digit number we've captured.

Now it gets a little odd: if the four digit number has a leading zero, the addition will (mostly!) result in a three digit result, and we want to preserve the leading zero. So the number we have, now stored in counter$ after the addition, is assigned to the active string and line 11 ensures that it's four characters long by adding leading zeroes if it's fewer. The output ands up in string$ and we can use that to build a new filename in line 12.

Finally, in line 13, we paste in the filename we've made.

Clear as mud? :D
Title: Re: Sequential file numbering
Post by: Paul (Lead Developer) on December 07, 2025, 12:28:52 PM
Very detailed! :) Thanks for sharing and explaining how it works.