Filters (12): Parent Folder Name

Would you like Bulk Rename Utility to offer new functionality? Post your comments here!

Filters (12): Parent Folder Name

Postby TheGhost78 » Wed Jul 31, 2024 2:27 am

It would be good to be able to select files based on whether or not the parent folder name is part of the filename. For example, if I want to prefix a filename with the parent folder name, I only want to select the files that don't already have the folder name in their filename. I would like to do it for lots of files/folders in one go, rather than filter manually per folder, so there would have to be a symbolic representation of the folder names, such as <Folder>, to put into the filter.
TheGhost78
 
Posts: 181
Joined: Fri Jul 19, 2024 11:25 am

Re: Filters (12): Parent Folder Name

Postby Admin » Wed Jul 31, 2024 10:10 am

Hi,

use this in the Filter (12) -> Condition:

Code: Select all
object('folder').search(name) == -1


It will include only files whose name is not found in their path.
Admin
Site Admin
 
Posts: 2923
Joined: Tue Mar 08, 2005 8:39 pm

Re: Filters (12): Parent Folder Name

Postby TheGhost78 » Wed Jul 31, 2024 8:33 pm

This only excludes files if the filename is exactly the same as the folder. I want to exclude them if the filename contains the folder name. For exampe:

Folder Name = AAAA
Excluded: Filename = AAAA - 2024-07-31 - BBBB.jpg
Included: Filename = 2024-07-31 - BBBB.jpg
TheGhost78
 
Posts: 181
Joined: Fri Jul 19, 2024 11:25 am

Filters12 Condition to exclude names beginning with ParentFo

Postby Luuk » Wed Jul 31, 2024 11:01 pm

To exclude names starting with ParentFolder, can use a condition like....... !name.startsWith(object('folder').replace(/.*\\(.+)\\$/,'$1'))
To exclude names having the whole ParentFolderName anywhere, its like... !name.match(object('folder').replace(/.*\\(.+)\\$/,'$1'))

For the example, can use this inside for Special(14) "Javascript Renaming"...
if (name.replace(/^(.+?) - .*/,'$1') != object('folder').replace(/.*\\(.+)\\$/,'$1')) {
newName = object('folder').replace(/.*\\(.+)\\$/,'$1 - ') + name}
(to only prefix "ParentFolderName - " when not already there)


But another way, without having any javascript/condition/mask, is to use AppendFolderName(9) with RegEx(1).
When AppendFolderName(9) uses ' - ' as its separator, then RegEx(1) needs a "Match" and "Replace" like...
^(.+? - )\1(.+)
\1\2
This does need Special(14) "Order" telling RegEx(1) to conduct after/below AppendFolderName(9).
This way RegEx(1) removes any repeating ParentFolderName prefix, so they wont get renamed.
Luuk
 
Posts: 809
Joined: Fri Feb 21, 2020 10:58 pm

Re: Filters (12): Parent Folder Name

Postby Admin » Thu Aug 01, 2024 2:48 am

In version 3.5.0.2 we have added:

object("container") : returns the name of the containing folder for the current object being processed.

This makes it easier to do the match vs. containing folders. Also if you want to ignore letter case use toLowerCase in JavaScript
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase
Admin
Site Admin
 
Posts: 2923
Joined: Tue Mar 08, 2005 8:39 pm

Re: Filters (12): Parent Folder Name

Postby Admin » Thu Aug 01, 2024 5:52 am

So you can use condition:

Code: Select all
name.search(object('container')) == -1


or for case-insensitive:

Code: Select all
name.toLowerCase().search(object('container').toLowerCase()) == -1


-1 means not found.
Admin
Site Admin
 
Posts: 2923
Joined: Tue Mar 08, 2005 8:39 pm

Re: Filters (12): Parent Folder Name

Postby TheGhost78 » Fri Aug 02, 2024 1:04 pm

Thanks, guys. From what's been posted above, I think Order should be separated out from Special (14) into its own category, and it should include Special (14) in the list of operations.
TheGhost78
 
Posts: 181
Joined: Fri Jul 19, 2024 11:25 am

Re: Filters (12): Parent Folder Name

Postby TheGhost78 » Fri Aug 02, 2024 1:06 pm

Maybe move it to the right of Name Segment under Copy/Move to Location (13).
TheGhost78
 
Posts: 181
Joined: Fri Jul 19, 2024 11:25 am

Re: Filters (12): Parent Folder Name

Postby TheGhost78 » Fri Aug 02, 2024 1:14 pm

In fact, it's probably worth renaming Filters (12) to Filters (A) and making Order (B), then renaming Special (14) to Special (12), so there is a distinction between which sections are actually involved in renaming and which sections are managing the renaming.
TheGhost78
 
Posts: 181
Joined: Fri Jul 19, 2024 11:25 am

Processing order

Postby Luuk » Fri Aug 02, 2024 3:27 pm

For myself, I though changing the order would be inside of the file-menu, like "Renaming Options".
So then after changing the order, it would make the sections present like RegEx(8) or Numbering(2).
But Im guessing its probably much harder to program? Again, many thanks for the latest improvements!!
Luuk
 
Posts: 809
Joined: Fri Feb 21, 2020 10:58 pm

Re: Filters (12): Parent Folder Name

Postby TheGhost78 » Fri Aug 02, 2024 4:31 pm

I make great use of the .bru files, and the renaming order is saved in those, which is good.
TheGhost78
 
Posts: 181
Joined: Fri Jul 19, 2024 11:25 am

Re: Filters (12): Parent Folder Name

Postby Admin » Sat Aug 03, 2024 12:27 am

Hi, we put the order at the end together with the other "special functions" as the other Special (14) functions are not movable atm.
We did think that we could then change the labels to RegEx(8) or Numbering(2) etc as well, if the order is changed, but we thought that it might become more confusing to refer to labels that change number when following instructions.
But it definitely could be done in the future. We are also experimenting with a new option to move the renaming controls into a separate window (optionally) and only show the criteria that's wanted, so see how that goes :)
Than you very much for the help with testing the beta and the feedback! please keep sending feedback much appreciated. 8)
Admin
Site Admin
 
Posts: 2923
Joined: Tue Mar 08, 2005 8:39 pm

Re: Filters (12): Parent Folder Name

Postby TheGhost78 » Sun Nov 24, 2024 4:03 am

If the parent folder contains [, ( or ) then it comes up with a syntax error using the three formulas below. It doesn't happen with ], { or } in the folder name.

name.search(object('container')) == -1
name.toLowerCase().search(object('container').toLowerCase()) == -1
!name.match(object('folder').replace(/.*\\(.+)\\$/,'$1'))


This formula works fine:

!name.startsWith(object('folder').replace(/.*\\(.+)\\$/,'$1'))
TheGhost78
 
Posts: 181
Joined: Fri Jul 19, 2024 11:25 am

Re: Filters (12): Parent Folder Name

Postby TheGhost78 » Sun Nov 24, 2024 8:17 am

I have some files where the folder name is contained within the filename and I just want to add " -" after it (and maybe "- " before it) in the filename. For example:

Folder name = AAAA
Filename = BBBB AAAA CCCC.jpg
New filename = BBBB AAAA - CCCC.jpg
or
New filename = BBBB - AAAA - CCCC.jpg

Can this be done with RegEx (1) or Javascript Renaming in Special (14)?
TheGhost78
 
Posts: 181
Joined: Fri Jul 19, 2024 11:25 am

Re: Filters (12): Parent Folder Name

Postby Admin » Mon Nov 25, 2024 4:36 am

Hi, what is the algorithm, find folder name in file name, and if found insert a - after the match ?
Admin
Site Admin
 
Posts: 2923
Joined: Tue Mar 08, 2005 8:39 pm

Next

Return to Suggestions