How to add file size in bytes to a file name

Bulk Rename Utility How-To's

How to add file size in bytes to a file name

Postby RenEnth » Tue Aug 23, 2022 4:38 am

Hello, my file naming scheme is based on a date YMD HMS (in Auto Date dropdown) and file size in bytes. For example, all of my photos have a name similar to: 190316123118-3810211-DSC09845.jpg. To do this automatically (sort of), I use two programs: BRU for the date format and TC for the file size in bytes. Is there a way to do everything in BRU?

190316123118-3810211-DSC09845.jpg =
    190316123118 - Date: 16 March 2019, 12:31:18
    3810211 - File size in bytes
    DSC09845 - File name from a camera
RenEnth
 
Posts: 3
Joined: Tue Aug 23, 2022 4:25 am

Add file-size in bytes as numbers-only

Postby Luuk » Tue Aug 23, 2022 10:24 am

With having the commercial license, javascript could use something like...
newName = name.replace(/^(\d{12}-)(.+)/, '$1' + '-' + object('size') + '$2')
This would insert the bytes inbetween your AutoDate(8) prefix and the original filenames.

Without having the paid javascript, it will probably need two separate renames, with something like...
First putting a checkmark inside of the menu for... "Display Options, List, Show File Sizes as, Bytes"
Then Add(7) could use a prefix like %z- with AutoDate(8) still conducting your same prefix settings.

But this does invent sizes looking like 3,810,211 B, so then another rename would still be needed.
RegEx(1) could fix them into numbers-only, with a checkmark inside of "v2" and a "Match" like...
(\G(?!^)|^\d{12}-).*?\K((?=[\d,]+ B-)(?<=\d),(?=\d{3})|(?<=\d) B(?=-))/g
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to add file size in bytes to a file name

Postby RenEnth » Tue Aug 23, 2022 12:29 pm

@Luuk

Thank you for taking the time to answer. Your proposal brings me closer to using just one program for all my renaming needs.
I will have a look at how to apply that regex, you crafted.
RenEnth
 
Posts: 3
Joined: Tue Aug 23, 2022 4:25 am

Add file-size in bytes as numbers-only

Postby Luuk » Tue Aug 23, 2022 2:34 pm

Its unfortunate, but the "Match" will only fix size-formats after the first-rename puts them inside of names like...
Any12digits-3,810,211 B-AnyText.txt ====> Any12digits-3810211-OriginalName.txt

And the only way I could discover to modify the %z size-variable was found inside of the menu "Display Options"!
So it does seem that without javascript, there is no way to omit the commas, or appending the " B" for bytes??
If I can discover any ways to better modify %z, then the 2nd-step might not even be needed.

You could always save both steps into a .bru-file, and then make a batch like...
"C:\Path\To\Your\Bulk Rename Utility.exe" "C:\Path\To\Your\Step1.bru"
"C:\Path\To\Your\Bulk Rename Utility.exe" "C:\Path\To\Your\Step2.bru"

So the batch would first open bru using Step1, then after clicking Rename, just close the application.
Then the batch would open bru using Step2, so you could click Rename to fix the size-formats.
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: Add file-size in bytes as numbers-only

Postby RenEnth » Tue Aug 23, 2022 2:48 pm

Luuk wrote:You could always save both steps into a .bru-file, and then make a batch like...
"C:\Path\To\Your\Bulk Rename Utility.exe" "C:\Path\To\Your\Step1.bru"
"C:\Path\To\Your\Bulk Rename Utility.exe" "C:\Path\To\Your\Step2.bru"

So the batch would first open bru using Step1, then after clicking Rename, just close the application.
Then the batch would open bru using Step2, so you could click Rename to fix the size-formats.


I was not aware I can do that. Thank you so much. You've been very helpful.


I've purchased 2 meals from a local "buy me a dinner" charity in your name as thanks.
RenEnth
 
Posts: 3
Joined: Tue Aug 23, 2022 4:25 am


Return to How-To