Highlighted

Use the API to get the LrFolder of an LrPhoto

Community Beginner ,
Dec 13, 2019

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?

Topics

SDK

Views

135

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Use the API to get the LrFolder of an LrPhoto

Community Beginner ,
Dec 13, 2019

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?

Topics

SDK

Views

136

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Dec 13, 2019

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.]

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...