Autonumber saving the last used number for later use

Post any Bulk Rename Command support requirements here. Open to all registered users.

Autonumber saving the last used number for later use

Postby nieuwenhuis007 » Wed Jan 15, 2020 3:56 pm

Hi,

I'm trying to periodically (25sec) rename files dropped in a folder by an FTP process:

- Number them sequentially with a total of eight numbers (e.g. 00000001, 00000002);
- Remove the rest of the filename including the extension;
- Saving the last autoincrement number is a file for later runs.

Everything works, only thing missing is the variable for the number and saving this to a file.

Is there a variable or an exit code i can use for storing the number ?
nieuwenhuis007
 
Posts: 1
Joined: Wed Jan 15, 2020 2:49 pm

Re: Autonumber saving the last used number for later use

Postby bru » Tue Jan 21, 2020 10:22 am

Nope, brc doesnt make it avail as a shell/env variable.
There's different ways to work around it, depending on your circumstance.
If you always rename all-files-with-an-extension, use something like:

@echo off
CD "C:\YourFTPFolder\"
::
:: If no renames, Set counter=1 (1st as file, then variable)
IF not exist "00000001" IF not exist "count" Echo.1>count
For /f %%A IN (count) DO set next=%%A
::
:: Resume naming (files with .ext)
Brc32 /IgnoreFileX /Pattern:"*.*" /RemoveName /AutoNumber:%next%:1:P::10:8 /execute
Ren count count.brc
::
:: Grab HighestRename# (Reverse sort NamesWithout.ext) then Goto Save
For /f %%B IN ('dir/b/a-d/o-n *.') DO Set high=%%B&&Goto Save
::
:Save counter (Strip Leading-0s, Add1, SaveToFile)
For /f "delims=0 tokens=*" %%C IN ("%high%") DO cmd /c Set /a next="%%C+1">count.brc
Ren count.brc count
::
:: Review Renames (delete this section if not desired)
echo.Done, press any key to exit.
pause>nul

That works for renaming all-files-with-an-extension.
With some of your files already numbered, a 1st-time run tries/fails to rename as 00000001, etc.
However, it also creates a proper resume-count file for all subsequent runs.

You could simplify it by keeping the count-file in another folder (versus renaming it back-and-forth).
Doubt I have all the details for your particular circumstance.
bru
 
Posts: 62
Joined: Wed Jan 31, 2018 7:35 pm


Return to BRC Support