Page 1 of 1

How do I pad after original filename?

Posted: 06 Jun 2021, 01:25
by adamlogan
I'm working in Plain File Mode, and am working with image and video files.

I am attempting to get all my images and media files to 16 digit filenames, they are named with the following format: 4-digit year 2 digit month 2 digit day 2 digit 24-hour-hour 2 digit minutes 2 digit seconds 2 digit milliseconds.

Some of my media files have less than 16 digits, I want to pad the end of these files so they have 16 digits so that they sort as expected by name in whatever file browser I use.

Some of my media files came from devices that do not write milliseconds, yet could take multiple pictures per second, and thus have extraneous stuff like hyphen and digit to keep them from overwriting each-other.

Looking through the documentation and the forum, I have not seen a way to use padding the way I am looking to. The default behavior is to add zeros behind a given string, not after it. Am I missing something?

Here is what I have.

Code: Select all

{original.pad (16, padding = "0")}
Image

Re: How do I pad after original filename?

Posted: 06 Jun 2021, 03:20
by rednoah
1.
You can pad to the right like so:

Code: Select all

{fn.padRight(16, '0')}

2.
You can make things more readable while you're at it:

Code: Select all

{
	def (d, i) = fn.tokenize('_')
	Date.parse('yyyyMMddHHmmss', d).format('yyyy-MM-dd_HH.mm.ss') + '_' + (i ?: '0')
}

Re: How do I pad after original filename?

Posted: 06 Jun 2021, 21:37
by adamlogan
@rednoah, Thanks.

I intentionally format my files this way since I want to be able to use command-line tools to manipulate my media files when a user-friendly or affordable GUI tool isn't an option. This approach sans separators minimizes the mess of using characters that confuse the shell or command-line tools, some of them expand or handle such characters, and it's a headache to figure out what especially when piping commands and whatnot, I prefer to do without them, I'm pretty comfortable with it now after a couple of years of doing this.