Page 1 of 1

extracting part of {folder}

Posted: 21 Jul 2024, 18:14
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.

Re: extracting part of {folder}

Posted: 21 Jul 2024, 18:55
by jchh
OK, got it.

`f.path.match()`

I was trying `f.match()` not realising that `path` had to be used.

Re: extracting part of {folder}

Posted: 22 Jul 2024, 04:50
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.

Re: extracting part of {folder}

Posted: 22 Jul 2024, 10:31
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?

Re: extracting part of {folder}

Posted: 22 Jul 2024, 11:09
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.

Re: extracting part of {folder}

Posted: 22 Jul 2024, 12:06
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

Re: extracting part of {folder}

Posted: 22 Jul 2024, 14:56
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.