Identifying jpegs without extension and recursively moving/renaming

Started by darinhouston, October 04, 2019, 11:09:31 PM

Previous topic - Next topic

darinhouston

I'm trying to use EXIFTOOL to recover photos from an old iPhone backup.

The idea is to recursively dig through folder structure of iPhone backup files (renamed without extensions) to identify jpegs and copy them to a common folder while adding a .jpg extension. 

Nothing I do seems to work.

StarGeek

Try something like
exiftool -ext * -if "$FileTypeExtension eq 'jpg'" "-Directory</path/to/new/directory/%f.$FileTypeExtension" -r /iphone/backup/

Because the files don't have extensions, you need to use -ext (extension) option with an asterisk to process all files.  Since you only want the jpgs, the -if option checks to make sure it's a jpg.  It will then copy to the new directory, keeping the original name (the %f) and adding the extension (see the Extra tags page).  The -r (recurse) option will recurse though all subdirectories.

If you're on Mac/Linux, swap the double/single quotes and make sure you're using regular quotes, not fancy quotes.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

darinhouston

Quote from: StarGeek on October 04, 2019, 11:28:07 PM
Try something like
exiftool -ext * -if "$FileTypeExtension eq 'jpg'" "-Directory</path/to/new/directory/%f.$FileTypeExtension" -r /iphone/backup/

Because the files don't have extensions, you need to use -ext (extension) option with an asterisk to process all files.  Since you only want the jpgs, the -if option checks to make sure it's a jpg.  It will then copy to the new directory, keeping the original name (the %f) and adding the extension (see the Extra tags page).  The -r (recurse) option will recurse though all subdirectories.

If you're on Mac/Linux, swap the double/single quotes and make sure you're using regular quotes, not fancy quotes.

Thanks, but it's not working. 

[darinmbp:~/test/images] darin% exiftool -ext * -if '$FileTypeExtension eq 'jpg'' '-Directory<images/%f.$FileTypeExtension' -r /Volumes/homes/maxwell/Backup/
  258 directories scanned
    0 image files read
[darinmbp:~/test/images

Here's an example output from one of the files in one of the folders. 

ExifTool Version Number         : 10.24
File Name                       : test.jpg
Directory                       : /Volumes/homes/maxwell/Backup/b2e0e152dcb6b9dafcbb9c0d051f054ea78bba0f/00
File Size                       : 57 kB
File Modification Date/Time     : 2019:10:04 14:40:51-05:00
File Access Date/Time           : 2019:10:04 14:40:52-05:00
File Inode Change Date/Time     : 2019:10:04 14:40:51-05:00
File Permissions                : rwx------
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Big-endian (Motorola, MM)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Y Cb Cr Positioning             : Centered
Exif Version                    : 0221
Components Configuration        : Y, Cb, Cr, -
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 457
Exif Image Height               : 102
Scene Capture Type              : Standard
Profile CMM Type                : appl
Profile Version                 : 4.0.0
Profile Class                   : Input Device Profile
Color Space Data                : RGB
Profile Connection Space        : XYZ
Profile Date Time               : 2016:01:01 00:00:00
Profile File Signature          : acsp
Primary Platform                : Apple Computer Inc.
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : APPL
Device Model                    :
Device Attributes               : Reflective, Glossy, Positive, Color
Rendering Intent                : Perceptual
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : appl
Profile ID                      : e6e9f2ad410a663dd5b3daa1e2075bd5
Profile Description             : Apple Wide Color Sharing Profile
Profile Copyright               : Copyright Apple Inc., 2016
Media White Point               : 0.9642 1 0.8251
A To B2                         : (Binary data 29772 bytes, use -b option to extract)
Chromatic Adaptation            : 1.04781 0.02289 -0.05017 0.02953 0.99051 -0.01706 -0.00925 0.01506 0.75191
A To B0                         : (Binary data 29772 bytes, use -b option to extract)
A To B1                         : (Binary data 29772 bytes, use -b option to extract)
Image Width                     : 457
Image Height                    : 102
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 457x102
Megapixels                      : 0.047

StarGeek

Quote from: darinhouston on October 05, 2019, 02:01:36 AM
[darinmbp:~/test/images] darin% exiftool -ext * -if '$FileTypeExtension eq 'jpg'' '-Directory<images/%f.$FileTypeExtension' -r /Volumes/homes/maxwell/Backup/

Check your quotes.  On Mac/Linux, single quotes on the outside of an argument, double quotes inside.  Try this, copy/paste if need be
-if '$FileTypeExtension eq "jpg" '
Take note that then quotes around jpg are double quotes ", not two single quotes ''
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

olball

Quote from: StarGeek on October 05, 2019, 02:56:26 AM
Check your quotes.  On Mac/Linux, single quotes on the outside of an argument, double quotes inside.  Try this, copy/paste if need be
-if '$FileTypeExtension eq "jpg" '

On Mac/Linux you need also to escape the asterisk in the extension switch: -ext "*" otherwise the shell is replacing the asterisk with all matching filenames in the current directory.

darinhouston

Thanks, good catch, but no cigar. 

Quotedarinmbp:~/test] darin% exiftool -ext * -if '$FileTypeExtension eq "jpg"' '-Directory<./%f.$FileTypeExtension' -r /Volumes/homes/maxwell/Backup/b2e0e152dcb6b9dafcbb9c0d051f054ea78bba0f/*
  258 directories scanned
    0 image files read
[darinmbp:~/test] darin%

Took a while to recurse, then nothing was in the present directory when done. 

Just to confirm... here's the first of the folders...  There are at least a couple of jpegs there.

[darinmbp:~/test] darin% exiftool /Volumes/homes/maxwell/Backup/b2e0e152dcb6b9dafcbb9c0d051f054ea78bba0f/00/* |grep Extension
File Type Extension             : plist
File Type Extension             : plist
File Type Extension             : png
File Type Extension             : flac
File Type Extension             : jpg
File Type Extension             : wav
File Type Extension             : png
File Type Extension             : plist
File Type Extension             : plist
File Type Extension             : plist
File Type Extension             : png
File Type Extension             : wav
File Type Extension             : gif
File Type Extension             : plist
File Type Extension             : gif
File Type Extension             : png
File Type Extension             : wav
File Type Extension             : plist
File Type Extension             : plist
File Type Extension             : plist
File Type Extension             : png
File Type Extension             : jpg
File Type Extension             : plist
File Type Extension             : flac
File Type Extension             : jpg
[darinmbp:~/test] darin%

StarGeek

Ok, try this instead
exiftool -ext '*' -if '$FileType=~/JPEG/i' '-Directory<./%f.$FileTypeExtension' -r /Volumes/homes/maxwell/Backup/b2e0e152dcb6b9dafcbb9c0d051f054ea78bba0f/

Copy/paste it.  Don't add an asterisk to the end.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

darinhouston

Interesting. Not sure why using a regex made such a difference.  But, it did move things. 

But, still not quite the desired outcome, though a step in the right direction.  It created a directory for each file and appended .jpg to the directory name and copied the photo into that directory without the extension.  I would like a single folder with all of these image files with .jpg appended to the file name.  The file name can stay the same or just be a sequential IMG_000x.jpg sort of naming.

StarGeek

Quote from: darinhouston on October 05, 2019, 11:09:31 AM
But, still not quite the desired outcome, though a step in the right direction.  It created a directory for each file and appended .jpg to the directory name and copied the photo into that directory without the extension.

Oops, my fault.  Don't know how I got that into my head.  Change Directory into FileName.
exiftool -ext '*' -if '$FileType=~/JPEG/i' '-FileName<./%f.$FileTypeExtension' -r /Volumes/homes/maxwell/Backup/b2e0e152dcb6b9dafcbb9c0d051f054ea78bba0f/
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).