Subject: Re: [Name Mangler Talk] Padding with zeros

From: Rob Griffiths <[email-masked]>
Date: Tue, 8 Jun 2021 12:24:18 -0700

On Jun 7, 2021, at 3:59 PM, Adam Logan <[email-masked]> wrote:

> I noticed 17 digit files get trimmed to 16 characters from the pad operation, that was a bit unexpected.

Well, it is how pad is defined to work—here's what it says in the help file (I added the bold):

Returns a constant formed from (source expression) by either removing characters from the end, or by appending as many occurrences of (padding expression) as necessary. If you enter a negative value for (length), the padding will be added at the beginning of (source expression).

> For some files this is helpful, for other times it is not. Is there a way to control or use these behaviors independently (pad, and trim)?

There is not, because the assumption behind pad is that if you want filenames of a certain length as defined in your pad command, that's what we're going to deliver, whether that means adding or removing characters. (There is a trim function, too, but it's different; it just removes leading and trailing spaces.)

> end of the filenames to maintain unique filenames from different softwares and different lengths (digits) for the filename. I know name mangler has that preference to maintain unique filenames. It would be awesome to have more control over the unique filename scheme as this seems to be where I'm struggling the most right now.

If you could give a more-detailed example of what you're trying to do (i.e. with a number of filenames of varying length and unique/nearly identical), I think you can probably get what you want using a sequence action as an additional step. But I need to better understand the longer names, and in particular, when you're needing the sequence numbers.

With all that said, the following will only apply the pad operation to filenames that are no more than 15 digits in length;

[if
	[findRegularExpression 
		"^\d{1,15}$" 
		in <name> 
		replace with "" 
	]
then
	name doesn't match expected format,
	so let's keep the original name:

	<name.extension>
else
	there were between 1 and 15 digits,
	so let's pad:

	[concatenate
		[pad 
			<name>
			to "16" 
			with "0" 
		]
		<.extension>
	]
]

-rob.

---

From: Adam Logan <[email-masked]>
Date: Mon, 7 Jun 2021 15:59:24 -0700 (PDT)

Thanks Rob.

I noticed 17 digit files get trimmed to 16 characters from the pad 
operation, that was a bit unexpected. For some files this is helpful, for 
other times it is not. Is there a way to control or use these behaviors 
independently (pad, and trim)?

I had been experimenting with stuffing the end of the filenames with 0's 
and then trimming to 16 digits in length, but it's a headache with 
different extraneous stuff at the end of the filenames to maintain unique 
filenames from different softwares and different lengths (digits) for the 
filename. I know name mangler has that preference to maintain unique 
filenames. It would be awesome to have more control over the unique 
filename scheme as this seems to be where I'm struggling the most right now.
On Sunday, June 6, 2021 at 6:03:59 AM UTC-7 Many Tricks wrote:

> On Jun 5, 2021, at 4:56 PM, Adam Logan <[email-masked]> wrote:
>
> > the extension. I am working with mixed extensions, so it is important to 
> preserve the extension rather than lopping it off and adding it back 
> manually in a subsequent step in Name Mangler. How do I achieve this?
>
> To recover the extension, you need to build the name in two connected 
> steps, via concatenate, which merges multiple steps into one operation:
>
> [concatenate
> [pad
> [findRegularExpression
> "(?<=^)(\d{1,15})(?=$)"
> in <name>
> replace with "$1"
> ]
> to "16"
> with "0"
> ]
> <.extension>
> ]
>
> Note: Please test on a copy of your files, just in case I messed something 
> up!
>
> > I'm surprised there isn't a user-friendly padding function without 
> having to wade into the advanced mode.
>
> Other than the article you linked to and this request, nobody else has 
> ever asked for padding abilities in non-Advanced mode. And it's a tricky 
> thing to make user-friendly, because of the ways you could specify where to 
> pad—via regex or fixed location, and the variety of characters you can pad 
> with, etc. I've added it to our list, but until/unless we get a lot more 
> requests, we'll probably leave it in Advanced mode (at least until whenever 
> we get to work on Name Mangler 4, and then we'll discuss adding it to the 
> non-Advanced functions.)
>
> regards;
> -rob.
>
>

---

From: Rob Griffiths <[email-masked]>
Date: Sun, 6 Jun 2021 06:03:57 -0700

On Jun 5, 2021, at 4:56 PM, Adam Logan <[email-masked]> wrote:

> the extension. I am working with mixed extensions, so it is important to preserve the extension rather than lopping it off and adding it back manually in a subsequent step in Name Mangler. How do I achieve this?

To recover the extension, you need to build the name in two connected steps, via concatenate, which merges multiple steps into one operation:

[concatenate
    [pad
        [findRegularExpression
            "(?<=^)(\d{1,15})(?=$)"
            in <name>
            replace with "$1"
        ]
        to "16"
        with "0"
    ]
    <.extension>
]

Note: Please test on a copy of your files, just in case I messed something up!

> I'm surprised there isn't a user-friendly padding function without having to wade into the advanced mode.

Other than the article you linked to and this request, nobody else has ever asked for padding abilities in non-Advanced mode. And it's a tricky thing to make user-friendly, because of the ways you could specify where to pad—via regex or fixed location, and the variety of characters you can pad with, etc. I've added it to our list, but until/unless we get a lot more requests, we'll probably leave it in Advanced mode (at least until whenever we get to work on Name Mangler 4, and then we'll discuss adding it to the non-Advanced functions.)

regards;
-rob.

---

From: Adam Logan <[email-masked]>
Date: Sat, 5 Jun 2021 16:56:58 -0700 (PDT)

Hi, what I'm shooting for is to rename (pad or trim) my photo collections 
to 16 digits formatted 4 digit year, 2 digit month 2 digit day 2 digit 
24-hour hour 2 digit minute 2 digit second 2 digit millisecond then underscore 
single digit numeral period extension for any photos that are taken during 
the same millisecond or for photos from cameras that don't output creation 
date that precise to the exif metadata of the photos.

2021060516052413_1.jpg

I am doing this so that my photo collections sort as expected by name, 
currently I have some photos that only have less than 16 digits and it's 
throwing off the ordering. I keep one massive folder with all my digital 
"negatives" photos, and it'd be really nice to be able to scroll using any 
old file explorer (these photos are stored on a NAS and easily accessible 
across various devices) and see them in chronological order.

I found this 
<https://www.robjwells.com/2016/10/padding-regex-groups-in-name-mangler/> article 
which gave me a good starting point to use the advanced mode in Name 
Mangler, and I modified it a little to suit my needs, however, I can't seem 
to recover the extension. I am working with mixed extensions, so it is 
important to preserve the extension rather than lopping it off and adding 
it back manually in a subsequent step in Name Mangler. How do I achieve 
this?

Here's what I have currently:

[pad
    [findRegularExpression
        "(?<=^)(\d{1,15})(?=$)"
        in <name>
        replace with "$1"
    ]
    to "16"
    with "0"
]

I'm surprised there isn't a user-friendly padding function without having 
to wade into the advanced mode.