Skip to main content
Participating Frequently
July 3, 2017
Answered

Relink Files based on the Original Filenames

After I edited and Renamed a few hundred Photos, I deleted the Folders with all the dng's. Now I only have the old Backup with all Photos, but there Names are, as they came from the camera. In Lightroom, I can see, that these original names are still in the Metadata. So shouldn't I be able to relink the Photos based in that name, without loosing the renaming? I really hope so! Is there a way??

This topic is closed to new replies. Start a new post to keep the conversation going.
john beardsworth
john beardsworthCorrect answer
Community Expert
July 3, 2017

Generating the dummy DNGs could be done automatically with a script. It would just loop through missing files and create a DNG with that filename.


This should do the job. Instructions are at the top.

Also save a dummy.dng on your desktop.

--[[

Copies DNG into missing file locations

SETUP INSTRUCTIONS

Copy all this quoted text into Notepad or TextEdit and save it as a text file on your desktop and call it "YOURFILENAME.lua".

Now you need to create a scripts folder:

    In Lightroom, choose Lightroom > Preferences (Mac OS) or Edit > Preferences (Windows).

    Choose the Preset tab and select Show Lightroom Presets folder.

    Create a folder in the Lightroom folder called Scripts.

    Copy the "YOURFILENAME.lua" script into the Scripts folder.

    Quit and reopen Lightroom.

You should now see a little scripts menu to the right of the Help menu. It has a single item YOURFILENAME.

--]]

------------------------------DON'T CHANGE BELOW

local LrPathUtils = import 'LrPathUtils'

local LrFileUtils = import 'LrFileUtils'

local LrTasks = import 'LrTasks'

local LrDialogs = import 'LrDialogs'

local SEP

if MAC_ENV then SEP = '/' else SEP = '\\' end

LrTasks.startAsyncTask( function()   

    srcPath = LrPathUtils.getStandardFilePath( 'desktop' ) .. SEP .. "dummy.dng"

    if LrFileUtils.exists( srcPath ) ~= "file" then

        LrDialogs.message("Create a dng called dummy.dng and put it on your desktop", srcPath)

        return false

    end

    local catalog = import "LrApplication".activeCatalog()   

    photos = catalog:getTargetPhotos()   

    filePaths = {}

    for i, photo in ipairs(photos ) do

        if photo:checkPhotoAvailability() == false then

            destPath = photo:getRawMetadata('path')   

            LrFileUtils.copy( srcPath, destPath )

        end

    end

    LrDialogs.showBezel("Finished", 5)

end)

19 replies

john beardsworth
Community Expert
Community Expert
July 3, 2017

Alternatively, you might be able to make DNGs from the files restored from the backup (you would do this in a temporary catalogue). If these files' names match the DNGs you have lost, the process of relinking would be easier. Of course, a lot depends on how you have renamed files.

How thoroughly have you deleted the folders of DNGs. Are they in the trash / recycle bin?

Translate
Participating Frequently
July 3, 2017

Unfortunately not. I don't drop balls, even in making mistakes ;o(

So far, I converted the files to DNG with the Adobe DNG Converter. The Names are still wrong, of course. There is a function in Lightroom to rename to the original filename. That would have made the relink smooth, but ironically, that only works, if the linked files are NOT missing ... (btw I don't understand that....)

I don't have to solve it today, so I hope for the geniuses answer )

Translate
john beardsworth
Community Expert
Community Expert
July 3, 2017

"I converted the files to DNG with the Adobe DNG Converter"

OK, what I am thinking is that you could import these DNG files into a temporary LR catalogue and rename them using the same renaming method that you used before. Would the filenames now correspond exactly to the filenames in the main catalogue?

Translate
dj_paige
Legend
July 3, 2017

First, I should like to point out that what I am about to say is the way I think LR works, but I haven't actually tried it, because I have not ever had this specific problem. (But you can try it and find out if I am right)

You can re-link renamed files, but you have to do the relinking one-by-one, as far as I know there is no automatic way to re-link all of them in one big batch operation (because of the renaming). When you re-link the photos, the name in Lightroom returns to the name of the actual file on your disk, thus your Lightroom files now have the name of the file provided by the camera. Whether or not the information in Lightroom under the "original name" field now shows the rename or the original, I do not know.

Side comment: if you are good at writing SQL code, you can probably write a program that fixes the problem in one big batch operation, but that is beyond my expertise (I write lots of SQL code, so it wouldn't be a difficult piece of code to write if you know SQL, but I have not ever written SQL for Lightroom's database)

Translate
johnrellis
Legend
July 3, 2017

dj_paige  wrote

if you are good at writing SQL code, you can probably write a program that fixes the problem in one big batch operation

A somewhat easier approach might to use SQL to extract the original filename of the photo and its current path into a text file, and then use shell scripting to rename and move the photos into place.  That SQL might be easier to write reliably, since it wouldn't have to update the catalog. There have been numerous posts in this forum and the Lightroom SDK forum over the years with fragments of SQL that would get someone experienced with SQL started.

I thought at first a plugin could extract this info, but I quickly verified that the original-filename field isn't available to plugins.

Translate
johnrellis
Legend
July 3, 2017

If you're reasonably good at scripting, you can exporting photo metadata from the catalog using a plugin, extract the same metadata from the restored files using ExifTool, match them up, and then rename the files in the script.  See this thread for more details: Re: Match lost files by meta data

Translate