Skip to main content
Inspiring
February 5, 2024
Question

Add metadata to files in another directory when not selected

  • February 5, 2024
  • 2 replies
  • 184 views

I can move and rename my files without any problem and add them back in the catalog.

But i'm having trouble how to go further with the moved files.

Adding metadata and so on, spend a whole day searching without any luck

 

function moveFiles(NewTargetDir, NewFileName, NewFileExtention)
	-- counters
	local Counter = "1"
	
	local catalog = LrApplication.activeCatalog()
	local result = catalog:withWriteAccessDo("Reimport photos", function(context)	
		photos = catalog:getTargetPhotos()
		for loop, photo in ipairs(photos) do
			local SourceFile = photo:getRawMetadata("path")
			local TargetFile  = NewTargetDir .. "/" .. NewFileName .. "-" .. string.format("%02d", Counter) .. "." .. NewFileExtention
			LrFileUtils.move(SourceFile, TargetFile)
			-- Add to catalog
			catalog:addPhoto(TargetFile)
			-- increase counter
			Counter = Counter + 1
		end		
	end)
end

 

 

I have tried to do it all in one loop but always an error.

So next thing is select images in the new directory, but here also errors

 

function UpdateMetadata(NewTargetDir)
	local catalog = LrApplication.activeCatalog()

	catalog:setActiveSources(NewTargetDir) 
	photos = catalog:setActiveSources(NewTargetDir) 
	
	for loop, photo in ipairs(photos) do
		photo:readMetadata()
                <photo: writeMetadata>
                < do something else>
LrDialogs.message(photo:getRawMetadata("path"))
	end
end

 

So anypointers would be appreciated 

Patrick

This topic has been closed for replies.

2 replies

Inspiring
February 6, 2024

Another thought would be:

Create a smart collection and as parameter would be filename starts with XXX

Move files with a filename that starts wit XXX to wherever I want.

But can I in the same plugin then select the smart catalog and do my stuff there with the renamed images

@johnrellis ?

Legend
February 5, 2024

I don't know Lua but typically in any language, you could add each object (array:push(TargetFile)) to an array when you work with it and then have a saved array to walk through later.

Inspiring
February 5, 2024

I wish that it was that 'easy', as I read the SDK normally you have something like:

catalog.selectedPhoto() and with that object you can do things.

But I have no idea how to bind this to a non selected object.

The catalog object does the manipulation of the LR database as I understand this.

Legend
February 5, 2024

Don't you need a way to keep track of which items you are going to modify?