When using an Execute Script Rule how can I determine the name of the subfolder that I am in when the rule executes?

When using a javascript as the execute script rule on a sub folder how can I determine the name of the subfolder that I am in when the rule executes?

Our subfolders are in the name of one the files custom metadata. so when moving or copying files I would like to change this piece of metadata to the name of the folder in which the file is being placed.

So what I require is to capture the subfolder name and use this text to populate my metadata field.

The answer above was perfect and using the "displayPath" option enabled me to capture the last 3 folders of the path so I could determine which metadata to use. for anyone else who maybe in the same situation please find a version of my code below and I hope it can help someone in the future.