• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Use the API to get the LrFolder of an LrPhoto

Community Beginner ,
Dec 13, 2019 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

414

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
community guidelines
LEGEND ,
Dec 13, 2019 Dec 13, 2019

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines