extracting part of {folder}

Support for macOS users
Post Reply
jchh
Posts: 49
Joined: 02 Nov 2020, 15:13

extracting part of {folder}

Post by jchh »

Hi,

I'd like to extract a specific folder name within {folder} that will always be one of 3 names, how would I go about doing it?

For example, if {folder} gives me:
`~/Downloads/example1/Movies/<name of movie>`

and the part I want is always one of `example1`, `example2`, `example3`, how can I extract that?

I would want the final filename to contain `[example1]`.

Thanks,
James.
jchh
Posts: 49
Joined: 02 Nov 2020, 15:13

Re: extracting part of {folder}

Post by jchh »

OK, got it.

`f.path.match()`

I was trying `f.match()` not realising that `path` had to be used.
User avatar
rednoah
The Source
Posts: 23924
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: extracting part of {folder}

Post by rednoah »

:idea: f.path will give you the entire file path.

:idea: folder.path will give you the folder path.

:idea: folder.name will give you the folder name.

:idea: You can do f.dir.name, f.dir.dir.name, f[0] , f[-2], etc to get individual path components.
:idea: Please read the FAQ and How to Request Help.
jchh
Posts: 49
Joined: 02 Nov 2020, 15:13

Re: extracting part of {folder}

Post by jchh »

thanks!

I couldn't find any reference to the `.path` element - where can I learn more about this and any others like it?
User avatar
rednoah
The Source
Posts: 23924
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: extracting part of {folder}

Post by rednoah »

:arrow: FileBot Groovy Expression Reference Documentation would be the entrance to the rabbit hole.


:idea: f.path is Groovy syntax for calling the File.getPath() function.
:idea: Please read the FAQ and How to Request Help.
jchh
Posts: 49
Joined: 02 Nov 2020, 15:13

Re: extracting part of {folder}

Post by jchh »

awesome - thanks!

I like rabbit holes!

could you expand a little on `f[-2]` - I can't seem to get that to work
User avatar
rednoah
The Source
Posts: 23924
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: extracting part of {folder}

Post by rednoah »

File.getAt() will give you the n-th path component. f[-2] is Groovy syntax for calling that method. -2 means 2nd element counting from the end. f[-2] is thus the same as f.dir.name and folder.name.
:idea: Please read the FAQ and How to Request Help.
Post Reply