How to rename recovered .jpg files to original Canon names in windows 10?

Started by gczerw, October 22, 2016, 05:01:15 PM

Previous topic - Next topic

gczerw

Using photorec, I have recovered a few thousand .jpg files that are in 5 directories.  I have tried the following command, found on the "http://www.cgsecurity.org/wiki/After_Using_PhotoRec" page, to no avail!

     The following command recreates the original directory layout and file names present on the card (for Canon cameras, tested with numerous photos from an EOS 20D), using the file number EXIF info. ExifTool works under both Windows and Linux.

exiftool -r '-FileName<IMG_${FileIndex}%c.%e' DIR

It uses FileIndex from EXIF information in file to rename to original filename, the %c is checking for duplicate names and appends other digit to the name. And it works recursively (-r).

As a test, I have placed one .jpg file in the "new" directory and have tried the following, with the result shown:

C:\Users\George\Downloads\testdisk-7.0\recover\new>exiftool "-FileName<IMG_${FileIndex}%c.%e" .
Warning: [minor] Tag 'FileIndex' not defined - ./IMG_102-0631.jpg
Warning: No writable tags set from ./IMG_102-0631.jpg
    1 directories scanned
    0 image files updated
    1 image files unchanged

Can someone tell me what is wrong here?  File information shown below.

======== ../new/dead.jpg
ExifTool Version Number         : 9.13
File Name                       : dead.jpg
Directory                       : ../new
File Size                       : 84 kB
File Modification Date/Time     : 2015:10:01 15:12:08-05:00
File Access Date/Time           : 2016:10:22 14:28:55-05:00
File Inode Change Date/Time     : 2016:10:22 13:09:27-05:00
File Permissions                : rw-r--r--
File Type                       : JPEG
MIME Type                       : image/jpeg
Exif Byte Order                 : Little-endian (Intel, II)
Image Description               :
Make                            : Canon
Camera Model Name               : Canon PowerShot ELPH 520 HS
Orientation                     : Horizontal (normal)
X Resolution                    : 180
Y Resolution                    : 180
Resolution Unit                 : inches
Modify Date                     : 2015:10:01 15:12:08
Y Cb Cr Positioning             : Co-sited
Exposure Time                   : 1/1250
F Number                        : 4.0
ISO                             : 100
Sensitivity Type                : Standard Output Sensitivity and Recommended Exposure Index
Exif Version                    : 0230
Date/Time Original              : 2015:10:01 15:12:08
Create Date                     : 2015:10:01 15:12:08
Components Configuration        : Y, Cb, Cr, -
Compressed Bits Per Pixel       : 3
Shutter Speed Value             : 1/1244
Aperture Value                  : 4.0
Max Aperture Value              : 4.0
Flash                           : Off, Did not fire
Focal Length                    : 6.5 mm
Macro Mode                      : Normal
Self Timer                      : Off
Quality                         : Fine
Canon Flash Mode                : Off
Continuous Drive                : Single
Focus Mode                      : Single
Record Mode                     : JPEG
Canon Image Size                : Small
Easy Mode                       : Manual
Digital Zoom                    : None
Contrast                        : Normal
Saturation                      : Normal
Sharpness                       : 0
Camera ISO                      : Auto
Metering Mode                   : Evaluative
Focus Range                     : Auto
AF Point                        : Face Detect
Canon Exposure Mode             : Program AE
Lens Type                       : Unknown (-1)
Max Focal Length                : 48 mm
Min Focal Length                : 4 mm
Focal Units                     : 1000/mm
Max Aperture                    : 4
Min Aperture                    : 8
Flash Bits                      : (none)
Focus Continuous                : Continuous
AE Setting                      : Normal AE
Image Stabilization             : On (2)
Zoom Source Width               : 3648
Zoom Target Width               : 3648
Spot Metering Mode              : Center
Manual Flash Output             : n/a
Auto ISO                        : 47
Base ISO                        : 200
Measured EV                     : 15.00
Target Aperture                 : 4
Target Exposure Time            : 1/1244
Exposure Compensation           : -1/3
White Balance                   : Auto
Slow Shutter                    : Off
Shot Number In Continuous Burst : 0
Optical Zoom Code               : 20
Flash Guide Number              : 0
Flash Exposure Compensation     : 0
Auto Exposure Bracketing        : Off
AEB Bracket Value               : 0
Control Mode                    : Camera Local Control
Focus Distance Upper            : 65.53 m
Focus Distance Lower            : 0 m
Bulb Duration                   : 0
Camera Type                     : Compact
Auto Rotate                     : None
ND Filter                       : Off
Self Timer 2                    : 0
Flash Output                    : 0
Canon Image Type                : IMG:PowerShot ELPH 520 HS JPEG
Canon Firmware Version          : Firmware Version 1.00
File Number                     : 111-2361
Camera Temperature              : 25 C
Canon Model ID                  : PowerShot ELPH 520 HS / IXUS 500 HS / IXY 3
Thumbnail Image Valid Area      : 0 0 0 0
Date Stamp Mode                 : Off
My Color Mode                   : Off
Firmware Revision               : 1.00 rev 4.00
Categories                      : (none)
AF Area Mode                    : Single-point AF
Num AF Points                   : 9
Valid AF Points                 : 1
Canon Image Width               : 640
Canon Image Height              : 480
AF Image Width                  : 3648
AF Image Height                 : 2736
AF Area Widths                  : 446 9560 -20012 10492 0 9560 0 -25160 24060
AF Area Heights                 : 485 -20012 5140 0 4720 0 19 3599 574
AF Area X Positions             : 0 10492 4717 10812 1 -20028 1 10400 10492
AF Area Y Positions             : 0 4720 0 0 4720 -25184 0 5140 -20012
AF Points In Focus              : 0
Primary AF Point                : 0
Intelligent Contrast            : Off
Image Unique ID                 : a62e5858bde2af8e6af173924ca2d5fa
Faces Detected                  : 0
Time Zone                       : +01:00
Time Zone City                  : n/a
Daylight Savings                : Off
Aspect Ratio                    : 4:3
Cropped Image Width             : 640
Cropped Image Height            : 480
Cropped Image Left              : 0
Cropped Image Top               : 0
VRD Offset                      : 0
User Comment                    :
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 640
Exif Image Height               : 480
Interoperability Index          : R98 - DCF basic file (sRGB)
Interoperability Version        : 0100
Related Image Width             : 640
Related Image Height            : 480
Focal Plane X Resolution        : 3333.333333
Focal Plane Y Resolution        : 3333.333333
Focal Plane Resolution Unit     : inches
Sensing Method                  : One-chip color area
File Source                     : Digital Camera
Custom Rendered                 : Normal
Exposure Mode                   : Manual
Digital Zoom Ratio              : 1
Scene Capture Type              : Standard
Owner Name                      :
Compression                     : JPEG (old-style)
Thumbnail Offset                : 5632
Thumbnail Length                : 3825
Rating                          : 0
Image Width                     : 640
Image Height                    : 480
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:2 (2 1)
Aperture                        : 4.0
Drive Mode                      : Single-frame Shooting
Image Size                      : 640x480
Lens                            : 4.0 - 48.0 mm
Lens ID                         : Unknown 4-48mm
Scale Factor To 35 mm Equivalent: 7.1
Shooting Mode                   : Program AE
Shutter Speed                   : 1/1250
Thumbnail Image                 : (Binary data 3825 bytes, use -b option to extract)
Circle Of Confusion             : 0.004 mm
Field Of View                   : 42.6 deg
Focal Length                    : 6.5 mm (35 mm equivalent: 46.2 mm)
Hyperfocal Distance             : 2.50 m
Lens                            : 4.0 - 48.0 mm (35 mm equivalent: 28.4 - 340.7 mm)
Light Value                     : 14.3
    1 directories scanned
    1 image files read

Phil Harvey

Quote from: gczerw on October 22, 2016, 05:01:15 PM
exiftool -r '-FileName<IMG_${FileIndex}%c.%e' DIR

It uses FileIndex from EXIF information in file to rename to original filename

... but FileIndex was not available in the output you gave.  There was a FileNumber tag though:

exiftool -r '-filename<IMG${FileNumber;s/.*-//}%c.%e' DIR

Here I have removed the directory number from the start of FileNumber using the advanced formatting expression s/.*-//

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gczerw

Thanks for that, but I get the following:

C:\Users\George\Downloads\testdisk-7.0\recover\new>exiftool "-filename<IMG${FileNumber;s/.*-//}%c.%e" .
    1 directories scanned
    1 image files updated

However the file has neither been renamed or moved elsewhere....

Phil Harvey

something was updated.  Add the -v3 option to get more details about what is happening.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gczerw

I really don't understand why this is occurring....

C:\Users\George\Downloads\testdisk-7.0\recover\new>exiftool -v3 "-filename<IMG${FileNumber;s/.*-//}%%c.%%e" .
    1 directories scanned
    0 image files read

C:\Users\George\Downloads\testdisk-7.0\recover\new>dir
Volume in drive C is Windows
Volume Serial Number is B02E-BE7C

Directory of C:\Users\George\Downloads\testdisk-7.0\recover\new

10/22/2016  04:46 PM    <DIR>          .
10/22/2016  04:46 PM    <DIR>          ..
10/01/2015  03:12 PM            85,694 dead.jpg
10/22/2016  04:01 PM         7,299,547 exiftool.exe
               2 File(s)      7,385,241 bytes
               2 Dir(s)  936,972,877,824 bytes free

C:\Users\George\Downloads\testdisk-7.0\recover\new>exiftool -v3 dead.jpg
File not found: dead.jpg

C:\Users\George\Downloads\testdisk-7.0\recover\new>exiftool -v3 .\dead.jpg
File not found: ./dead.jpg

C:\Users\George\Downloads\testdisk-7.0\recover\new>exiftool -v3 C:\Users\George\Downloads\testdisk-7.0\recover\new\dead.jpg
File not found: C:/Users/George/Downloads/testdisk-7.0/recover/new/dead.jpg

Phil Harvey

This could happen if there were an invisible character (eg. a space) in the file extension.  Otherwise, there is something funny that is wrong with your disk.  I would try typing this:

rename "dead<tab> test.jpg

(press the tab key to complete the name, then rename the file to something you know)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gczerw

Okay, that worked.  Attached is the output of:

C:\Users\George\Downloads\testdisk-7.0\recover\new>exiftool -v3 test1.jpg >exif.txt

It is too long to paste...

Phil Harvey

I don't know why you posted the output of that command.  I suggested adding -v3 to the command where you are trying to write FileName.  But it seems the problem is that there were invisible characters in the file name so ExifTool didn't process it.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gczerw

Sorry, I misunderstood...

C:\Users\George\Downloads\testdisk-7.0\recover\new>exiftool -v3 "-filename<IMG${FileNumber;s/.*-//}%%c.%%e" .
======== ./test1.jpg
Setting new values from ./test1.jpg
Writing File:FileName
'./test1.jpg' --> './IMG2361%.%jpg'
    + FileName = './IMG2361%.%jpg'
    1 directories scanned
    1 image files updated

C:\Users\George\Downloads\testdisk-7.0\recover\new>dir
Volume in drive C is Windows
Volume Serial Number is B02E-BE7C

Directory of C:\Users\George\Downloads\testdisk-7.0\recover\new

10/23/2016  10:27 AM    <DIR>          .
10/23/2016  10:27 AM    <DIR>          ..
10/23/2016  10:27 AM            36,938 exif.txt
10/22/2016  04:01 PM         7,299,547 exiftool.exe
10/01/2015  03:12 PM            85,694 test1.jpg
               3 File(s)      7,422,179 bytes
               2 Dir(s)  936,877,940,736 bytes free

C:\Users\George\Downloads\testdisk-7.0\recover\new>

File neither renamed nor moved anywhere!

Phil Harvey

I wonder if the "%" characters are causing a problem (although I am surprised that ExifTool didn't receive an error status when the rename failed).  You only need the doubled "%" characters in the argument to -d or in a .BAT file.  Try this:

exiftool -v3 "-filename<IMG${FileNumber;s/.*-//}%c.%e" .

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gczerw

No luck...but clearly something is amuck here!  Watch the sequence of events....

C:\Users\George\Downloads\testdisk-7.0\recover\new>exiftool -v3 "-filename<IMG${FileNumber;s/.*-//}%c.%e" .
    1 directories scanned
    0 image files read

C:\Users\George\Downloads\testdisk-7.0\recover\new>dir
Volume in drive C is Windows
Volume Serial Number is B02E-BE7C

Directory of C:\Users\George\Downloads\testdisk-7.0\recover\new

10/23/2016  10:27 AM    <DIR>          .
10/23/2016  10:27 AM    <DIR>          ..
10/23/2016  10:27 AM            36,938 exif.txt
10/22/2016  04:01 PM         7,299,547 exiftool.exe
10/01/2015  03:12 PM            85,694 test1.jpg
               3 File(s)      7,422,179 bytes
               2 Dir(s)  936,846,929,920 bytes free

C:\Users\George\Downloads\testdisk-7.0\recover\new>rename test1.jpg test2.jpg

C:\Users\George\Downloads\testdisk-7.0\recover\new>dir
Volume in drive C is Windows
Volume Serial Number is B02E-BE7C

Directory of C:\Users\George\Downloads\testdisk-7.0\recover\new

10/24/2016  09:41 AM    <DIR>          .
10/24/2016  09:41 AM    <DIR>          ..
10/23/2016  10:27 AM            36,938 exif.txt
10/22/2016  04:01 PM         7,299,547 exiftool.exe
10/01/2015  03:12 PM            85,694 test2.jpg
               3 File(s)      7,422,179 bytes
               2 Dir(s)  936,859,758,592 bytes free

C:\Users\George\Downloads\testdisk-7.0\recover\new>exiftool -v3 "-filename<IMG${FileNumber;s/.*-//}%c.%e" .
======== ./test2.jpg
Setting new values from ./test2.jpg
Writing File:FileName
'./test2.jpg' --> './IMG2361.jpg'
    + FileName = './IMG2361.jpg'
    1 directories scanned
    1 image files updated

C:\Users\George\Downloads\testdisk-7.0\recover\new>dir
Volume in drive C is Windows
Volume Serial Number is B02E-BE7C

Directory of C:\Users\George\Downloads\testdisk-7.0\recover\new

10/24/2016  09:41 AM    <DIR>          .
10/24/2016  09:41 AM    <DIR>          ..
10/23/2016  10:27 AM            36,938 exif.txt
10/22/2016  04:01 PM         7,299,547 exiftool.exe
10/01/2015  03:12 PM            85,694 test2.jpg
               3 File(s)      7,422,179 bytes
               2 Dir(s)  936,878,288,896 bytes free

C:\Users\George\Downloads\testdisk-7.0\recover\new>

Out of curiosity, I just did a chkdsk of the drive.  No errors found.

Phil Harvey

OK.  That should have worked.  I have never seen this specific problem before but try disabling your antivirus software to see if it is preventing ExifTool from renaming the file.  Also, you may try a simpler command and try a different file.  (eg. exiftool -filename=test2.txt test1.txt)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gczerw

No change in behavior on Windows 10 desktop machine with antivirus shutdown.

However, out of curiousity, I took some files, went upstairs to the Windows 8.1 desktop machine and tried there...  SOME PROGRESS!

C:\Users\George\Downloads\new>exiftool -v3 "-filename<IMG${FileNumber;s/.*-//}%c.%e" .
======== ./dead.jpg
Setting new values from ./dead.jpg
Writing File:FileName
'./dead.jpg' --> './IMG2361.jpg'
    + FileName = './IMG2361.jpg'
    1 directories scanned
    1 image files updated

C:\Users\George\Downloads\new>dir
Volume in drive C has no label.
Volume Serial Number is B4FC-9759

Directory of C:\Users\George\Downloads\new

10/24/2016  05:55 PM    <DIR>          .
10/24/2016  05:55 PM    <DIR>          ..
10/01/2015  03:12 PM            85,694 IMG2361.jpg
10/24/2016  05:29 PM         7,299,547 exiftool.exe
10/24/2016  05:55 PM    <DIR>          fixed
               2 File(s)      7,385,241 bytes
               3 Dir(s)  227,520,618,496 bytes free


C:\Users\George\Downloads\new>exiftool -v3 "-filename<IMG${FileNumber}%c.%e" .
======== ./dead.jpg
Setting new values from ./dead.jpg
Writing File:FileName
'./dead.jpg' --> './IMG111-2361.jpg'
    + FileName = './IMG111-2361.jpg'
    1 directories scanned
    1 image files updated

C:\Users\George\Downloads\new>dir
Volume in drive C has no label.
Volume Serial Number is B4FC-9759

Directory of C:\Users\George\Downloads\new

10/24/2016  05:55 PM    <DIR>          .
10/24/2016  05:55 PM    <DIR>          ..
10/01/2015  03:12 PM            85,694 IMG111-2361.jpg
10/24/2016  05:29 PM         7,299,547 exiftool.exe
10/24/2016  05:55 PM    <DIR>          fixed
               2 File(s)      7,385,241 bytes
               3 Dir(s)  227,520,618,496 bytes free

Interesting that I'm getting results on the Windows 8.1 machine.  The filenames were changed in the current directory.  However but no appropriate Canon numbered directories were created and no files were moved.

Canon DCIM directory nomenclature is, for example 111_10, and filename nomenclature is IMG_xxxx.jpg.  So how should I proceed to get those results?

Phil Harvey

Did you try turning off Windows Defender on the Windows 10 machine?

To also set the directory to ###_## as you described, you could do this:

exiftool "-filename<${FileNumber;tr/-/_/;$_=substr($_,0,6)}/IMG${FileNumber;s/.*-//}%c.%e" .

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gczerw

1.  Defender was off on the Windows 10 machine.

2.  That command did NOTHING on the Windows 8.1 machine (defender also off on it).  But it says that it did!!!  I can't find that new directory or file anywhere!

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\George>cd Downloads/new

C:\Users\George\Downloads\new>exiftool -v3 "-filename<${FileNumber;tr/-/_/;$_=substr($_,0,6)}/IMG${FileNumber;s/.*-//}%c.%e" .
======== ./dead.jpg
Setting new values from ./dead.jpg
Writing File:FileName
'./dead.jpg' --> '111_23/IMG2361.jpg'
Created directory 111_23
    + FileName = '111_23/IMG2361.jpg'
    1 directories scanned
    1 directories created
    1 image files updated

C:\Users\George\Downloads\new>dir
Volume in drive C has no label.
Volume Serial Number is B4FC-9759

Directory of C:\Users\George\Downloads\new

10/24/2016  08:25 PM    <DIR>          .
10/24/2016  08:25 PM    <DIR>          ..
10/01/2015  03:12 PM            85,694 dead.jpg
10/24/2016  05:29 PM         7,299,547 exiftool.exe
10/24/2016  08:25 PM    <DIR>          fixed
               2 File(s)      7,385,241 bytes
               3 Dir(s)  225,855,995,904 bytes free

This is weird!!!