Copy link to clipboard
Copied
This should be easy, but there doesn't seem to be an obvious way to get the LrFolder of an LrPhoto in the API. For collections, there's photo:getContainedCollections(), but no equivalent for folders.
My best attempt:
function getFolder(photo)
local path = photo:getRawMetadata("path")
local _, _, folderPath, filename = string.find(path, "^(.*)/([^/]*)$")
return catalog:getFolderByPath(folderPath)
end
The string processing is non-portable (assumes "/" as path separator) and krufty. It would help if there were a LrFileUtils.parentDirectory function, but there is not.
Is there anything in the API to improve on this?
Copy link to clipboard
Copied
Use LrPathUtils to get the parent directory:
catalog:getFolderByPath (LrPathUtils.parent (photo:getRawMetadata ("path")))
[Use the reply button under the first post to ensure replies sort properly.]