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.