Copy link to clipboard
Copied
Hi,
When importing media from mobile devices, I ended up with a lot of files under the wrong folders. I'm creating a Library plugin to relocate them based on capture time. My strategy is to call LrCatalog.addPhoto() on the file path and that has worked nicely in my testing.
Now I have 2 copies of the same file in LR, the original copy in the wrong directory and the new copy. Is there a way to achieve something like LrCatalog.removePhoto() to get rid of the old copy? I know I can remove the file with LrFileUtils, but how to update the catalog?
Thanks
Yi
The SDK won't let you remove photos from the catalog proper. In your case, a script or plugin can use LrFileUtils.delete (photo.path) to remove a photo from disk. Then when you're done, manually invoke Library > Find All Missing Photos, select the thumbnails marked missing, and remove them from the catalog.
Alternatively, when your script deletes a photo from disk, it can also add it to a collection "To Be Deleted". You can then manually remove the photos in that collection from the catalog.
Copy link to clipboard
Copied
The SDK won't let you remove photos from the catalog proper. In your case, a script or plugin can use LrFileUtils.delete (photo.path) to remove a photo from disk. Then when you're done, manually invoke Library > Find All Missing Photos, select the thumbnails marked missing, and remove them from the catalog.
Alternatively, when your script deletes a photo from disk, it can also add it to a collection "To Be Deleted". You can then manually remove the photos in that collection from the catalog.
Copy link to clipboard
Copied
Thanks! The first method worked, although it took quite a while to run since there were a lot of photos.
I don't fully understand the second approach though. If it worked, it'd be a great optimization. I'm able to move the photos to a "To Be Deleted" collection. But removing the photos from that collection afterwards affected only the collection itself. It didn't help remove them from their folders, which is what I tried to achieve. Did I miss anything?
Copy link to clipboard
Copied
"But removing the photos from that collection afterwards affected only the collection itself. It didn't help remove them from their folders, which is what I tried to achieve. Did I miss anything?"
You'll need to use the menu command Photo > Remove Photos From Catalog (see the menu item for the keyboard shortcut). When in a collection, Delete / Backspace just removes the photo from the collection.
Copy link to clipboard
Copied
Worked beautifully! Thanks!
Copy link to clipboard
Copied
In case anyone's interested https://github.com/jiaxuan/fixfolders.lrdevplugin
Copy link to clipboard
Copied
Resurrecting this discussion a sec.
Recurrently I get a bug and can't trash my files:https://community.adobe.com/t5/lightroom-classic-discussions/p-lr-cannot-delete-files-from-a-drive-t...
Today I have explored the alternative of using the the SDK in attempt to skip this bug.
LrFileUtils.moveToTrash( path ) can be used BUT as @johnrellis said LrC is not automatically removing the photos form the catalog AND I discovered that those file can't be "put back" (on Mac) form the trash.
Not as dangerous as deleting immediately but still I fid this dangerous.
These API are pretty inferior compared to built in Delete or Remove.
We have catalog:addPhoto so to me it would make sense to have also catalog:removePhoto.
.