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?
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.
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?
"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.
Worked beautifully! Thanks!