Pad file names only?

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

Pad file names only?

Postby cday » Mon Jun 11, 2018 5:21 pm

Command line utilities (BRC and NConvert, for example) read source files without leading zeros in the filename in non-numeric (alphanumeric or ASCII) sort order, 1 - 10 - 11 - 2 for example. As a result, when a multi-page output file is produced some pages are in the wrong order.

I don't see any way to simply pad existing file numbers so that they are read in the correct numeric sequence? So that files with an arbitrary alphanumeric prefix and number such as abcd1 are renamed abcd001, etc.

Padding with leading zeros is a basic function in any Windows renaming utility, but the /AUTONUMBER parameter reads the source files, in non-numeric order, and renumbers them adding padding if specified, so the order will still be incorrect... If the file numbers were only padded, the order in which files were read wouldn't matter.

So is there a way of just adding padding? Or a simple workaround that could be included in a batch file?
cday
 
Posts: 4
Joined: Mon Jun 11, 2018 4:05 pm

Re: Pad file names only?

Postby therube » Mon Jun 11, 2018 8:58 pm

Maybe something like this?
And I'm sure I haven't taken all into consideration, & also needing multiple passes.
Basing this on wanting a padding of 3.

Code: Select all
BRC  /REGEXP:([A-z\s_-]+)(\d$):\1---00\2

So find "aphas" & underscores & spaces & dashes, followed by a single digit (so 0-9) (at the end of the name, $) & then pad that with 00.
So: 001 002 003 ...
Code: Select all
Filename 9000.TXT requires no changes
Filename 9000_1.TXT would be renamed to _---001.TXT
Filename 9000_2.TXT would be renamed to _---002.TXT
Filename 9000_3.TXT would be renamed to _---003.TXT
Filename BRC32.exe requires no changes
Filename BRU_3001 requires no changes
Filename Lupas50 requires no changes

(As you can see, not quite right ;-).)

Then again:
Code: Select all
BRC  /REGEXP:([A-z\s_-]+)(\d\d$):\1---0\2

The same only look for 00-99 & pad that with a single 0.
So: 000-099
Code: Select all
Filename BRC32.exe would be renamed to BRC---032.exe
Filename Lupas50 would be renamed to Lupas---050


If a name ends in \d\d\d, it is already as wanted, so no changes needed.


Oh, \1----, is only there like that to differentiate things as I was testing.
Adjust the number of \d with the corresponding number of '0' needed for the padding you want.
therube
 
Posts: 1025
Joined: Mon Jan 18, 2016 6:23 pm

Re: Pad file names only?

Postby cday » Mon Jun 11, 2018 9:18 pm

Thanks for your reply, I am not into REGEXP myself yet, but I'll try it.

The use case is entirely general, so in principle the prefix before the file number could contain almost any character, including possibly a number or numbers, and not necessarily in the English language.

The problem came up on the XnView-NConvert forum a while back, when a poster needed to create multipage PDF files and discovered that some early pages were in the wrong order, so I'm ideally looking for as far as possible a general solution that I can post there, or possibly use myself if the need arises.

Development of BRC seems to have stopped a while back, but perhaps ideally there would be a /PAD parameter added to provide a simple general solution, if that is technically possible.
cday
 
Posts: 4
Joined: Mon Jun 11, 2018 4:05 pm

Re: Pad file names only?

Postby cday » Sat Jun 16, 2018 8:03 pm

I have now made a series of tests, and think I understand how to use REGEXP in the way you suggested above. To use REGEXP I had to first install the pcre.dll utility, which I now belatedly see was actually included in the BRC download ZIP.

Could you please confirm that the following code (intended to pad PNG files s1.png s2.png ... in a folder 'Process' to 001.png 002.png ... ) is as you would expect:

Code: Select all
BRC32.exe /DIR:Process /PATTERN:"*.png" /REGEXP:([A-z\s_-]+)(\d$):\000\2 /EXECUTE
BRC32.exe /DIR:Process /PATTERN:"*.png" /REGEXP:([A-z\s_-]+)(\d\d$):\00\2 /EXECUTE
BRC32.exe /DIR:Process /PATTERN:"*.png" /REGEXP:([A-z\s_-]+)(\d\d\d$):\0\2 /EXECUTE

In my tests, where 's' is placeholder alphanumeric text, output is as follows:

Code: Select all
s0.png   -->  0000.png
s1.png   -->  0001.png
s2.png   -->  0002.png
s10.png  -->  0010.png
s11.png  -->  0011.png
s999.png -->  0999.png

The source file number range accepted by the above code is from '0' to '999' : conversion of '1000' and above fails, as at least one zero must always be inserted.

There must also be at least one non-numeric prefix character present otherwise the code fails, so as 1.png, 2.png ... could be a common use case, that is a significant limitation.

Does the REGEXP code above remove all possible non-numeric characters, or are there any further terms that could be inserted to make the conversion as general as possible?

Any comments or suggestions welcome...
cday
 
Posts: 4
Joined: Mon Jun 11, 2018 4:05 pm


Return to BRC Support