folder failure

All about user-defined episode / movie / file name format expressions
Post Reply
UKenGB
Posts: 49
Joined: 04 Jan 2017, 09:26

folder failure

Post by UKenGB »

I want to cut up the path to the file. {folder} gives me the string, but trying to do something like folder.before... or folder.replaceAll just gives an error, something about "No signature of method..." If I instead try the same replacement on e.g. fn, it works fine.

So what is it about the 'folder' values that causes it to fail? Should this not work? If not, why not? Seems like a perfectly valid format to me.
User avatar
rednoah
The Source
Posts: 22974
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: folder failure

Post by rednoah »

{folder} gives you a File object, not a String object. It's the same as {file.parentFile}.

Use {folder.name} or {folder.path} to get a String for the folder name/path. Once you have a String you can use all the String methods on that object.
:idea: Please read the FAQ and How to Request Help.
UKenGB
Posts: 49
Joined: 04 Jan 2017, 09:26

Re: folder failure

Post by UKenGB »

Ok, understood. Thanks.

Any way to easily get the folder of the folder? IOW the parent of the parent?

Also, am I right that replaceAll() can only take a string as the replacement? Is there any way to replace some text with a calculated value, like from a ternary conditional?
User avatar
rednoah
The Source
Posts: 22974
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: folder failure

Post by rednoah »

Parent Parent Path:

Code: Select all

{folder.parent}
Parent Parent Name:

Code: Select all

{folder.parentFile.name}
Arbitrary Path Section:

Code: Select all

{file[-3..-2].path}
Arbitrary Replacement Logic:

Code: Select all

{'1 2 3'.replaceAll(/\d/){ it.toInteger() * 3 }}
:idea: Please read the FAQ and How to Request Help.
Post Reply