• Welcome to the Lightroom Queen Forums! We're a friendly bunch, so please feel free to register and join in the conversation. If you're not familiar with forums, you'll find step by step instructions on how to post your first thread under Help at the bottom of the page. You're also welcome to download our free Lightroom Quick Start eBooks and explore our other FAQ resources.
  • Stop struggling with Lightroom! There's no need to spend hours hunting for the answers to your Lightroom Classic questions. All the information you need is in Adobe Lightroom Classic - The Missing FAQ!

    To help you get started, there's a series of easy tutorials to guide you through a simple workflow. As you grow in confidence, the book switches to a conversational FAQ format, so you can quickly find answers to advanced questions. And better still, the eBooks are updated for every release, so it's always up to date.

Library module Removing JPGs imported as part of RAW+JPG

Status
Not open for further replies.

PhilBurton

Lightroom enthusiast (but still learning)
Premium Classic Member
Joined
Nov 16, 2015
Messages
2,634
Location
California, USA
Lightroom Experience
Intermediate
Lightroom Version
Classic
Lightroom Version
Lightroom Classic 7.4
Operating System
  1. Windows 10
This web page describes a complicated Lightroom procedure for removing superfluous JPGs that were imported along with RAW files. That is exactly what I did for a long time and now I want to get rid of these unnecessary files.

Section 1.2 describes the procedure. This section contains the following:

So if you have been storing all those JPEG images, what do you do? How do you get rid of them now? Unfortunately, Lightroom has no way of simply deleting those JPEG images, but there are a couple of tricks you can employ to get rid of them – keep on reading this article to find out how!

But why can't I just delete all those JPGs when Lightroom is not running and then start up Lightroom and sync data?

Phil Burton
 
Joined
May 12, 2011
Messages
3,575
Location
Canada
Lightroom Experience
Advanced
Lightroom Version
Classic
If you imported treating JPEGs as separate files, that ought to work. If not, you probably wouldn't even need to sync, although LR would coneinue to mention "+jpg", which would only be a problem if you care about the cosmetics of how your files are listed.
 

PhilBurton

Lightroom enthusiast (but still learning)
Premium Classic Member
Joined
Nov 16, 2015
Messages
2,634
Location
California, USA
Lightroom Experience
Intermediate
Lightroom Version
Classic
Hal,

I imported the JPGs as part of NEF+JPG as just one image. I have about 200 MB of these JPGs that I want to get rid of. Can I just delete those without Lightroom going bonkers about missing files? and if it does go bonkers can a simple sync operation fix that? That's what I care about.

Phil Burton
 
Joined
Jul 2, 2015
Messages
11,653
Location
Netherlands
Lightroom Experience
Power User
I imported the JPGs as part of NEF+JPG as just one image. I have about 200 MB of these JPGs that I want to get rid of. Can I just delete those without Lightroom going bonkers about missing files? and if it does go bonkers can a simple sync operation fix that? That's what I care about.
They won't become missing files, because they are not in the catalog as files. They are only in the catalog as sidecars, so the worst that could happen is that Lightroom shows you the icon for 'changed metadata'.
 
Joined
Aug 7, 2018
Messages
59
Location
Wichita Falls, TX
Lightroom Experience
Intermediate
Lightroom Version
Classic
I went through this a couple months back when cleaning up my catalog from my days of shooting Raw+jpg. If you just delete the files LR will continue to show raw+jpg regardless. Irked me to no end, because if the file is gone, I don't want LR to show there is two file types. Eventually figured out you need to go to Preferences>General>and click the option for Treat Jpg as Separate Files. Then select the folder with both file types, right click and select the option Synchronize folder. After syncing, LR will show show both files separately. To remove, you can select them individually, but I found it easier to select the Metadata filter at the top of the Library pane, then change one of the options to File Type, then select Jpg. With only those files showing its a snap to select and delete. This will enable you to keep a clean catalog without extraneous metadata floating around.
 
Last edited:

PhilBurton

Lightroom enthusiast (but still learning)
Premium Classic Member
Joined
Nov 16, 2015
Messages
2,634
Location
California, USA
Lightroom Experience
Intermediate
Lightroom Version
Classic
Joined
Oct 8, 2007
Messages
5,905
Location
London
Lightroom Experience
Power User
Phil, I use this script. It loops through the selected raw files and deletes the corresponding jpeg. Afterwards, LR will still show raw + jpeg.

Copy everything below my name into a text file.

John

Code:
--[[

Loops through selected raw files and deletes the corresponding jpeg

SETUP INSTRUCTIONS
Temporarily save this file onto 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.
Human beings can ignore anything below this line
--]]


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()   

       
    local catalog = import "LrApplication".activeCatalog()   
    photos = catalog:getTargetPhotos()   
    for i, photo in ipairs(photos ) do
        path = photo:getRawMetadata("path")
        jpegPath = LrPathUtils.replaceExtension( path, 'jpg' )
        if LrFileUtils.exists( jpegPath ) == 'file' then
        newFolder = LrPathUtils.parent( jpegPath ) ..SEP..'JPEG'
        LrFileUtils.createDirectory( newFolder )
        newPath = newFolder .. SEP .. LrPathUtils.leafName( jpegPath )
        -- LrDialogs.message(        LrPathUtils.parent( jpegPath ) )
        LrFileUtils.move( jpegPath, newPath )
        end
    end

    LrDialogs.showBezel("Finished", 5)
end)
 
Last edited:
Joined
Aug 7, 2018
Messages
59
Location
Wichita Falls, TX
Lightroom Experience
Intermediate
Lightroom Version
Classic
Thanks Phil, happy to help out and hope it accomplishes what you need. Sounds like you don't like extraneous crud left behind either. Thanks for link too. I visit Photography Life about once a week and missed that article. A very good read. Interesting that after Nasim Synchronized the folder, it seems the Jpg and Raw were separate. Mine was left Raw, Jpg, Raw, Jpg in the same folder. Couldnt figure out how he did that. Then again mine were imported years before like he described in the beginning. Maybe that has something to do with it.
 

PhilBurton

Lightroom enthusiast (but still learning)
Premium Classic Member
Joined
Nov 16, 2015
Messages
2,634
Location
California, USA
Lightroom Experience
Intermediate
Lightroom Version
Classic
Phil, I use this script. It loops through the selected raw files and deletes the corresponding jpeg. Afterwards, LR will still show raw + jpeg.

Copy everything below my name into a text file.

John



--[[

Loops through selected raw files and deletes the corresponding jpeg

SETUP INSTRUCTIONS
Temporarily save this file onto 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.
--]]


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()


local catalog = import "LrApplication".activeCatalog()
photos = catalog:getTargetPhotos()
for i, photo in ipairs(photos ) do
path = photo:getRawMetadata("path")
jpegPath = LrPathUtils.replaceExtension( path, 'jpg' )
if LrFileUtils.exists( jpegPath ) == 'file' then
newFolder = LrPathUtils.parent( jpegPath ) ..SEP..'JPEG'
LrFileUtils.createDirectory( newFolder )
newPath = newFolder .. SEP .. LrPathUtils.leafName( jpegPath )
-- LrDialogs.message( LrPathUtils.parent( jpegPath ) )
LrFileUtils.move( jpegPath, newPath )
end
end

LrDialogs.showBezel("Finished", 5)
end)

John,

I really appreciate it that you put together this script. Before I run this script and do something that I can't easily recover from (just in case), some questions, and then a request. I have no doubt that if I learned Lua and could really understand this script, I wouldn't need to write this note at all.

  • In the two lines starting "local SEP" for a Windows system, does Lua want the directory folder SEP to be a double backslash? Normally in Windowsland, the double backslash indicates a systemname, as in:
\\MySystem\Media\2018 - would access the 2018 folder on the Media drive on system MySystem.
  • Does this script actually delete JPGs or move them to a new directory?
  • Does this script check for a matching NEF file before deleting a JPG?
My request is to list out both NEF and JPG files with their pathnames and date/time. is that possible?

Thank you,

Phil Burton
 

Hoggy

Never take life, or anything in it, too seriously.
Joined
Nov 20, 2012
Messages
527
Location
Wisconsin
Lightroom Experience
Advanced
Lightroom Version
  • In the two lines starting "local SEP" for a Windows system, does Lua want the directory folder SEP to be a double backslash? Normally in Windowsland, the double backslash indicates a systemname, as in:
\\MySystem\Media\2018 - would access the 2018 folder on the Media drive on system MySystem.

While I'm not John, obviously.. :) I have been trying to learn some Lua while biding my time in replacing my slow aging laptop. So hopefully I can try answering some of your Q's - and hopefully John can chime in with how close or far off I am. Although I have yet to get around to the LR-specific libraries/functions in the LR SDK (i.e. The 'import' clauses in the beginning).

In Lua, the character '\' is an escape character, similar to that in regexp's, but '/' isn't.. So by writing '\\' - that actually equates to a '\' as the separator in directory names. Also, btw, the '..' is the concatenate operator, which you may have already guessed.

  • Does this script actually delete JPGs or move them to a new directory?
  • Does this script check for a matching NEF file before deleting a JPG?
My request is to list out both NEF and JPG files with their pathnames and date/time. is that possible?

It looks to me like it first tests for a matching jpeg and then moves it to a new "JPEG" directory in the directory in which it is found.

But I'm still interested in hearing what John has to say, cause I want to know if my Lua lessons have taught me anything so far.

My guess is the last thing you mentioned is possible, but I'm not sure how useful that would be, as you would still have to find them manually afterwards.
Overall, I still think think the easiest method would be to do the synchronize folder after checking the 'treat as separate photos' preference item if you prefer to take a more hands-on cautious approach.
 
Joined
Oct 8, 2007
Messages
5,905
Location
London
Lightroom Experience
Power User
Phil,

You really don't need to understand anything below the line, but you have indeed understood it, as has Hoggy :

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

But as you asked.... I use the variable SEP because the script often needs to concatenate the folder path and the file name, so it needs to know whether to use a "\" or "/". The complication requiring "\\" is that as Hoggy wrote, "\" is an escape character, meaning that it forces the program to accept the following text character, even if that character means something particular in the code's language. Lua would normally think "\" meant that I was forcing it to read or interpret a slash and a double quote , when I really want it to only read a slash. The escape \ in "\\" tells it to read a single slash.

And Hoggy is again right in reading the script as moving the JPEGs to a new folder. In fact, I had written the script a while ago and had named it "Delete JPEGs" and forgotten that I had changed the code to moving. I''ve just changed my own script copy so it does what it says it does! But now I think about it, that moving method is a safer way for me to publish the script!

"Does this script check for a matching NEF file before deleting a JPG?"

It loops through the selected raw files, and targets any JPG with the same name in the same folder. It certainly might check that the raw file exists and preserve the JPG in those cases, but I am assuming the user simply wants to dump JPGs shot as part of a normal raw+JPG workflow. As for deleting rather than moving, deletion is a simple change which involves commenting out one line and inserting another.
Code:
-- LrFileUtils.move( jpegPath, newPath )
LrFileUtils.delete( jpegPath )

John
 
Last edited:

PhilBurton

Lightroom enthusiast (but still learning)
Premium Classic Member
Joined
Nov 16, 2015
Messages
2,634
Location
California, USA
Lightroom Experience
Intermediate
Lightroom Version
Classic
Phil,

You really don't need to understand anything below the line, but you have indeed understood it, as has Hoggy :

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

But as you asked.... I use the variable SEP because the script often needs to concatenate the folder path and the file name, so it needs to know whether to use a "\" or "/". The complication requiring "\\" is that as Hoggy wrote, "\" is an escape character, meaning that it forces the program to accept the following text character, even if that character means something particular in the code's language. Lua would normally think "\" meant that I was forcing it to read or interpret a double quote , when I really want it to read a slash. "\\" tells it to read a single slash.

And Hoggy is again right in reading the script as moving the JPEGs to a new folder. In fact, I had written the script a while ago and had named it "Delete JPEGs" and forgotten that I had changed the code to moving. I''ve just changed my own script copy so it does what it says it does! But now I think about it, that moving method is a safer way for me to publish the script!

"Does this script check for a matching NEF file before deleting a JPG?"

It loops through the selected raw files, and targets any JPG with the same name in the same folder. It certainly might check that the raw file exists and preserve the JPG in those cases, but I am assuming the user simply wants to dump JPGs shot as part of a normal raw+JPG workflow. As for deleting rather than moving, deletion is a simple change which involves commenting out one line and inserting another.
Code:
-- LrFileUtils.move( jpegPath, newPath )
LrFileUtils.delete( jpegPath )

John
John,

Thanks. I don't know Lua, but I do know the concept of escape characters. All those years of working with software engineers hasn't been a total waste. ;)

Actually I much prefer the "move" functionality to the "delete" functionality. My underlying concern is that I want to delete only those JPGs that came straight out of the camera. If I had done any editing on the JPG, I would want to keep it, if only as a reminder that I had done some edits, and probably also did an export.

Phil
 
Last edited:

Hoggy

Never take life, or anything in it, too seriously.
Joined
Nov 20, 2012
Messages
527
Location
Wisconsin
Lightroom Experience
Advanced
Lightroom Version
Actually I much prefer the "move" functionality to the "delete" functionality. My underlying concern is that I want to delete only those JPGs that came straight out of the camera. If I had done any editing on the JPG, I would want to keep it, if only as a reminder that I had done some edits, and probably also did an export.

But if you had imported them as raw+jpg, with that preference item unchecked, then LR wouldn't have done anything at all with those jpgs. I'm not sure if there's a way to test those jpgs if you had done editing with something else - at least nothing sure-fire that could be tested against.

You could also run John's script, which will move the jpgs into a separate directory and leaving (for now) the raws showing as 'raw+jpg', then go into those "JPEG" directories in the folder panel to do any manual checking. Then if you want to get rid of the 'raw+jpg' display, then do a synchronize-folder afterwards.
By using the "LrFileUtils.move" function, it should keep them in the catalog - as otherwise there would be other ways to move them if it wasn't intended for them to remain in the catalog. Therefore you could always use a smart-collection rule of: Folder Contains "JPEG" to single those out.

It might be nice if there was a subforum on here for Lua learning - or maybe I hadn't noticed one yet. :)
 
Joined
Oct 8, 2007
Messages
5,905
Location
London
Lightroom Experience
Power User
My script was written on the assumption that I import the raw+jpeg pairs in the default "single file" method. I only shoot raw+jpeg with my Fuji as I want to take advantage of the Embedded/Sidecar previews and the Fuji's raw files don't contain full size previews. LR can use the full size jpegs, but I don't really want to keep these forever - hence the script should delete them.

By using the "LrFileUtils.move" function, it should keep them in the catalog

Yes, but it's important to stress that LrFileUtils.move is purely an OS operation. It moves the physical file but Adobe don't let you update the file path in the catalogue. So if you imported both files, using LrFileUtils.move would move the jpegs but leave them missing in the catalogue.

Therefore you could always use a smart-collection rule of: Folder Contains "JPEG" to single those out.

Since 7.4 you might use the filter box at the top of the Folders panel.

John
 

Hoggy

Never take life, or anything in it, too seriously.
Joined
Nov 20, 2012
Messages
527
Location
Wisconsin
Lightroom Experience
Advanced
Lightroom Version
Yes, but it's important to stress that LrFileUtils.move is purely an OS operation. It moves the physical file but Adobe don't let you update the file path in the catalogue. So if you imported both files, using LrFileUtils.move would move the jpegs but leave them missing in the catalogue.

Wow.. That is entirely unexpected. I had a look-see at the SDK reference and it didn't say anything about it registering in the catalog or not, so I assumed it would have had to.
So there's really no way to do it in the API?? I browsed the SDK reference a bit and saw a 'catalog:addPhoto', but saw nothing about any kind of 'removePhoto', nor, like you said, anything like 'updatePhotoLocation'. And now I would guess that 'LrFileUtils.delete' must also be a purely OS operation as well?

Is there even any call to start a 'synchronize folder'? I can't see anything so far, during this initial perusal.
This must be indicative of the lack of love the SDK gets - that I always hear mentioning of.


........ At least I found my Golden Ticket function: 'LrShell.openPathsViaCommandLine'. My main interest in learning Lua is to create a fully functioning kind of "TPG LR Backup" that was abandoned -- with more control over [re-]compression algorithms with 7zip (using Modern7z plugins to use Zstandard), and envisioned control over how many backups are kept or deleted (like maybe a tiered system for keeping older backups as they age). Ehh... Pipe dreams right now. :cool2: I know a standard backup program would be easier, except for the fact that I always manually recompress the catalog backups anyways using Zstandard - and I'm a firm supporter of automation! :happy:
 
Joined
Oct 8, 2007
Messages
5,905
Location
London
Lightroom Experience
Power User
All those understandings of the SDK are correct.
 
Status
Not open for further replies.
Top