Hi
I am quite new to exiftool and also Linux command line as well.
I hope someone can help me along my path to get a process for handling my photos.
What I want is to copy photos from one folder on my NAS and sort the phots into folders of year-month, based on when the photo was taken. I also want to re-name the photo to date and time it was created.
However - not all photos will have EXIF-data and those photos I would like to move to a different folder where I gather all photos missing EXIF-data so I later manually can process these.
I have written a script I run on a Linux server.
Unfortunately, I have encountered a small problem. When I run this line, exiftool does not recognize Create date of some photos - i.e. the photo is not re-namned and not copied to the expected folder.
exiftool -o . -d '/mnt/synology_foto_backup/User_1/Foto_Backup/%Y-%m-%B/%y-%m-%d %H.%M.%S%%+2nc.%%e' '-filename>createdate' /mnt/synology_homes/User_1/Foto_Nya
I have identified some photos missing EXIF-data and have a work-around. But some photos exiftool does not seem to recognize create date and does not copy to the desired folder, nor change the name. The more surprising aspect is that a copy of these photos end up on the linux server in the folder from where the script is executed.
My guess is that exiftool on Linux server reads the file, change the name and move the photo to the desired folder. But if it somehow, after reading the photo file, does not find create date, the photo gets stuck on the linux server instead of moved to a new location on the NAS.
I have examples of EXIF-data from 2 different photos that behave in this weird way:
SG edit: Changed from [table] to [code]
Photo 1
ExifTool Version Number : 12.76
File Name : AQBU0960.MP4
Directory : .
File Size : 5.0 MB
File Modification Date/Time : 2025:06:11 16:11:04+00:00
File Access Date/Time : 2025:06:11 16:11:18+00:00
File Inode Change Date/Time : 2025:06:11 16:11:04+00:00
File Permissions : -rw-r--r--
File Type : MP4
File Type Extension : mp4
MIME Type : video/mp4
Major Brand : MP4 Base Media v1 [IS0 14496-12:2003]
Minor Version : 0.2.0
Compatible Brands : isom, iso2, avc1, mp41
Media Data Size : 4984970
Media Data Offset : 48
Movie Header Version : 0
Create Date : 0000:00:00 00:00:00
Modify Date : 0000:00:00 00:00:00
Time Scale : 1000
Duration : 0:01:03
Preferred Rate : 1
Preferred Volume : 100.00%
Preview Time : 0 s
Preview Duration : 0 s
Poster Time : 0 s
Selection Time : 0 s
Selection Duration : 0 s
Current Time : 0 s
Next Track ID : 3
Track Header Version : 0
Track Create Date : 0000:00:00 00:00:00
Track Modify Date : 0000:00:00 00:00:00
Track ID : 1
Track Duration : 0:01:03
Track Layer : 0
Track Volume : 0.00%
Image Width : 1920
Image Height : 1080
Graphics Mode : srcCopy
Op Color : 0 0 0
Compressor ID : avc1
Source Image Width : 1920
Source Image Height : 1080
X Resolution : 72
Y Resolution : 72
Bit Depth : 24
Video Frame Rate : 14.843
Matrix Structure : 1 0 0 0 1 0 0 0 1
Media Header Version : 0
Media Create Date : 0000:00:00 00:00:00
Media Modify Date : 0000:00:00 00:00:00
Media Time Scale : 8000
Media Duration : 0:01:03
Media Language Code : und
Handler Description : SoundHandler
Balance : 0
Audio Format : mp4a
Audio Channels : 2
Audio Bits Per Sample : 16
Audio Sample Rate : 8000
Handler Type : Metadata
Handler Vendor ID : Apple
Encoder : Lavf57.83.100
Image Size : 1920x1080
Megapixels : 2.1
Avg Bitrate : 635 kbps
Rotation : 0
Photo 2
ExifTool Version Number : 12.76
File Name : IMG_7539.PNG
Directory : .
File Size : 7.7 MB
File Modification Date/Time : 2025:06:11 16:11:04+00:00
File Access Date/Time : 2025:06:11 16:24:21+00:00
File Inode Change Date/Time : 2025:06:11 16:11:04+00:00
File Permissions : -rw-r--r--
File Type : PNG
File Type Extension : png
MIME Type : image/png
Image Width : 1125
Image Height : 2436
Bit Depth : 16
Color Type : RGB
Compression : Deflate/Inflate
Filter : Adaptive
Interlace : Noninterlaced
Profile Name : kCGColorSpaceDisplayP3
Profile CMM Type : Apple Computer Inc.
Profile Version : 4.0.0
Profile Class : Display Device Profile
Color Space Data : RGB
Profile Connection Space : XYZ
Profile Date Time : 2022:01:01 00:00:00
Profile File Signature : acsp
Primary Platform : Apple Computer Inc.
CMM Flags : Not Embedded, Independent
Device Manufacturer : Apple Computer Inc.
Device Model :
Device Attributes : Reflective, Glossy, Positive, Color
Rendering Intent : Perceptual
Connection Space Illuminant : 0.9642 1 0.82491
Profile Creator : Apple Computer Inc.
Profile ID : ecfda38e388547c36db4bd4f7ada182f
Profile Description : Display P3
Profile Copyright : Copyright Apple Inc., 2022
Media White Point : 0.96419 1 0.82489
Red Matrix Column : 0.51512 0.2412 -0.00105
Green Matrix Column : 0.29198 0.69225 0.04189
Blue Matrix Column : 0.1571 0.06657 0.78407
Red Tone Reproduction Curve : (Binary data 32 bytes, use -b option to extract)
Chromatic Adaptation : 1.04788 0.02292 -0.0502 0.02959 0.99048 -0.01706 -0.00923 0.01508 0.75168
Blue Tone Reproduction Curve : (Binary data 32 bytes, use -b option to extract)
Green Tone Reproduction Curve : (Binary data 32 bytes, use -b option to extract)
Exif Byte Order : Big-endian (Motorola, MM)
Orientation : Horizontal (normal)
Date/Time Original : 2025:02:07 13:25:42
User Comment : Screenshot
Exif Image Width : 1125
Exif Image Height : 2436
XMP Toolkit : XMP Core 6.0.0
Date Created : 2025:02:07 13:25:42
Image Size : 1125x2436
Megapixels : 2.7
Anyone who can help me how I can solve the problem and get Exiftool to recognize date the phot was captured so it does not get copied to my linux server? I only want it on my NAS.
Thanks
I didn't read your whole post, but it seems you want to set the file name from CreateDate: ie. '-filename<createdate'
What you were doing ('-filename>createdate' with the point towards CreateDate) will set CreateDate from the FileName.
- Phil
Sorry - my mistake when I wrote the post I put the <> wrong way. The code I am using is as you suggest
exiftool -o . -d '/mnt/synology_foto_backup/User_1/Foto_Backup/%Y-%m-%B/%y-%m-%d %H.%M.%S%%+2nc.%%e' '-filename<createdate' /mnt/synology_homes/User_1/Foto_Nya
So there must be another problem
Do the files that end up in the exiftool directory actually have a
CreateDate tag in them?
Use this command to view all the date/time tags in the file
exiftool -time:all -G1 -a -s /path/to/files/Quote from: Gus on June 11, 2025, 12:27:28 PMBut some photos exiftool does not seem to recognize create date and does not copy to the desired folder, nor change the name. The more surprising aspect is that a copy of these photos end up on the linux server in the folder from where the script is executed.
There are two possibilities here. One is FAQ #16, Why doesn't ExifTool rename my video files? (https://exiftool.org/faq.html#Q16), though this applies to any file type that exiftool cannot write, e.g. mp3, ogg, MKV. The other possibility is that the files do not have a
CreateDate tag.
If the files have a
CreateDate, then they should be copied to the path in the date format string. This is what is documented in the
-o (
-out) option (https://exiftool.org/exiftool_pod.html#o-OUTFILE-or-FMT--out)
QuoteWhen writing only FileName and/or Directory "pseudo" tags, -o causes the file to be copied instead of moved
But if the file doesn't have a
CreateDate, then the above does not apply. Instead, the copy goes to the path indicated by the
-o, which is the dot/current directory.
What you want is to have a fallback directory for the files without a
CreateDate. See note #1 under the
-TAG[+-^]=[VALUE] option (https://exiftool.org/exiftool_pod.html#TAG---VALUE).
Example
exiftool -o . -d '/mnt/synology_foto_backup/User_1/Foto_Backup/%Y-%m-%B/%y-%m-%d %H.%M.%S%%+2nc.%%e' '-Directory=/mnt/synology_foto_backup/User_1/Foto_Backup/No_Create_Dates' '-filename<createdate' /mnt/synology_homes/User_1/Foto_Nya
Thank you very much
If you look at the first post, Photo 2 - the 3rd row from the end - it says Date Created - and that photo is still ending up in the exiftool directory. Same for Photo 1 but there Create Date is in the middle so harder for to describe exactly where.
However - at the moment (I live in Sweden) it is working hours and I'll try your suggestion later today when I have time.
Quick add on question for a newbie: Why do I have to specify -Directory=/... in the argument regarding No_Create_Dates and not in the first argument where the photo is copied to Y-m-folder?
I just ran this simple test to check the general principle:
The command is run from the directory containing the images and the sub-directories "changed" and "unchanged" are created within the same directory.
exiftool -o unchanged -d 'changed/%Y-%m-%B/%y-%m-%d %H.%M.%S%%+2nc.%%e' '-filename<createdate' .
In the case where the createdate exists in the original file and is valid (i.e. not 00:00:00 00:00:00 for example) then the files are copied to the changed sub-directory and renamed as expected.
Where createdate does not exist or is invalid the unnamed files are copied to the unchanged directory.
All files are copied rather than moved.
This same principle should work if you change the directory names.
Thank you very much.
Since I am so new to this, is it possible to add an incremental number to the photos copied to the unchanged directory, if there already is a photo with the same name in the directory?
Otherwise I see a risk that there already is a photo in the "unchanged" directory with the same name and the photo thus is not copied and instead end up on the Linux server from where I run the Exiftool script.
Should it be like this: unchanged/$filename+2nc.%%e
Quote from: Gus on June 12, 2025, 08:34:26 AMThank you very much.
Since I am so new to this, is it possible to add an incremental number to the photos copied to the unchanged directory, if there already is a photo with the same name in the directory?
Otherwise I see a risk that there already is a photo in the "unchanged" directory with the same name and the photo thus is not copied and instead end up on the Linux server from where I run the Exiftool script.
Should it be like this: unchanged/$filename+2nc.%%e
In your date format you could do this to add a sequence number:
%y-%m-%d %H.%M.%S %%.2nc.%%eor this just adds a digit if there are duplicates:
%y-%m-%d %H.%M.%S%%c.%%e
Quote from: Gus on June 12, 2025, 03:54:08 AMIf you look at the first post, Photo 2 - the 3rd row from the end - it says Date Created - and that photo is still ending up in the exiftool directory.
Yes, I should have looked at that data closer, but it's harder to figure out data dumps like this when the command from FAQ #3 (https://exiftool.org/faq.html#Q3) isn't used.
Your data only verifies what I said. There is no
CreateDate in that file.
CreateDate date is usually either an EXIF tag (common in JPEGs from a camera) or a Quicktime tag, as is the case of your first file.
DateCreated is a different tag from the
XMP-Photoshop group. It has to be added to the file, usually through some sort of Digital Asset Management (DAM) program such as Lightroom or DigiKam.
Example of how each tag looks when you use the
-s (
-short) option (https://exiftool.org/exiftool_pod.html#s-NUM--short) which prints tag names, not description.
C:\>exiftool -time:all --system:all -G1 -a -s y:\!temp\Test4.jpg
[ExifIFD] CreateDate : 2025:06:12 12:00:00
[XMP-photoshop] DateCreated : 2025:01:01 12:00:00
QuoteQuick add on question for a newbie: Why do I have to specify -Directory=/... in the argument regarding No_Create_Dates and not in the first argument where the photo is copied to Y-m-folder?
It is the fallback command for files that don't have a
CreateDate. Without the fallback, the
-o . option takes effect and copies the file to the current directory. The dot as a file path always refers to the current directory.
Edit: See post belowAnd actually, I may have gotten that wrong. I'll have to double-check, but it probably should be
'-Filename=/mnt/synology_foto_backup/User_1/Foto_Backup/No_Create_Dates/%F'
Quote from: greybeard on June 12, 2025, 06:00:39 AMAll files are copied rather than moved.
Do you want your files copied or moved? You seem to be using the words interchangable in your first post, when they are different operations. I assumed you wanted them copied because you included the
-o option. If you wanted them moved, then you need to remove that option.
Quote from: Gus on June 12, 2025, 08:34:26 AMThank you very much.
Since I am so new to this, is it possible to add an incremental number to the photos copied to the unchanged directory, if there already is a photo with the same name in the directory?
Otherwise I see a risk that there already is a photo in the "unchanged" directory with the same name and the photo thus is not copied and instead end up on the Linux server from where I run the Exiftool script.
Should it be like this: unchanged/$filename+2nc.%%e
Filename is a tag, and it includes the extension. This would mean that the command would use a tag copy
< instead of assignment
=. See Common Mistake #5c (https://exiftool.org/mistakes.html#M5) for details
The better solution would be to change what I said in this post (https://exiftool.org/forum/index.php?msg=93516) into this
'-Filename=/mnt/synology_foto_backup/User_1/Foto_Backup/No_Create_Dates/%f%+2nc.%e'%f is the base filename without the extension. Using the capital F like in my previous post is the filename plus the extension.
%+2nc breaks down like this.
%c is a copy number added when there's a duplicate name collision.
The
2 is the number width. Leading 0s will be padded if the number is 0-9.
The
n starts the count at 1 instead of 0. Note that this means the first file will be just the filename and no count number. The second file will have a count of 2. See the below example
The plus sign means that the copy number will have a leading underscore sign when the copy number is used.
Example of how the count with
%+2nc would look
C:\>exiftool -G1 -a -s -testname=file%+2nc.%e Y:\!temp\x\y\z
'Y:/!temp/x/y/z/c.jpg' --> 'Y:/!temp/x/y/z/file.jpg'
'Y:/!temp/x/y/z/d.jpg' --> 'Y:/!temp/x/y/z/file_02.jpg'
'Y:/!temp/x/y/z/a.jpg' --> 'Y:/!temp/x/y/z/file_03.jpg'
'Y:/!temp/x/y/z/b.jpg' --> 'Y:/!temp/x/y/z/file_04.jpg'
There are a lot of possible modifiers to the
% filename variables which can be found under the
-w (
-TextOut) option (https://exiftool.org/exiftool_pod.html#w-EXT-or-FMT--textOut). Remove the
n if you want the first copy to start at
01 instead of
02
Putting all of this together,
This command will created copies of the files Foto_Backup directory based upon the CreateDate or DateCreated tag if it exists. Otherwise, it will be copied to the Foto_Backup/No_Create_Dates directory.
exiftool -o . -d '/mnt/synology_foto_backup/User_1/Foto_Backup/%Y-%m-%B/%y-%m-%d %H.%M.%S%%+2nc.%%e' '-Filename=/mnt/synology_foto_backup/User_1/Foto_Backup/No_Create_Dates/%f%-2c.%e' '-filename<DateCreated' '-filename<CreateDate' /mnt/synology_homes/User_1/Foto_Nya
This command will move files to the new directories. They will only exist in the new directories, not the original directories
exiftool -d '/mnt/synology_foto_backup/User_1/Foto_Backup/%Y-%m-%B/%y-%m-%d %H.%M.%S%%+2nc.%%e' '-Filename=/mnt/synology_foto_backup/User_1/Foto_Backup/No_Create_Dates/%f%-2c.%e' '-filename<DateCreated' '-filename<CreateDate' /mnt/synology_homes/User_1/Foto_Nya
StarGeek - you're absolutely wonderful. Thank you so much.
When I try it on my small test-batch of 5 photos, IT WORKS !!
... and thank you for all your additional comments. Really helps me understand.
Quote from: Gus on June 12, 2025, 03:59:35 PMReally helps me understand.
That's the hardest part. Metadata is an absolute mess in regard to the standards (see xkcd Standards (https://xkcd.com/927/)). And everybody's situation and problems are always a bit different, so it's difficult to have an easy answer.
One additional note since your original post had a PNG file as an example. PNG files have very poor metadata support in most apps and rarely have any metadata unless it was specifically added at some point. Or are AI generated, as most AI image generation adds some specialized metadata about how the file was created.
Quick follow up question I have not found an answer to.
For the solution copy or move the file to a directory based on date, the script sort of ends with. .%S%%+2nc.%%e'
whereas if the EXIF-file does not contain information about date, the script ends with No_Create_Dates/%f%-2c.%e
can someone please explain what the difference is between these two alternatives? Why is %f needed in the later script and why 2nc.%%e in one script and 2c.%e in the other? What does the extra % in front of the e do?
It has to do with the location of the percent signs.
The part that has two percent signs is part of the
-d (
-dateFormat) option (https://exiftool.org/exiftool_pod.html#d-FMT--dateFormat). To avoid possible collisions between the date format codes (such as
%f->fractional seconds) and the file format codes (
%f->base filename), the file format codes have their percent signs doubled so they are not treated as date format codes. From Common Date Format Codes (https://exiftool.org/filename.html#codes)
QuoteExifTool file name format codes may be used inside a date format string when a date/time tag is used to set the value of the FileName or Directory tags via the command-line interface. In this case, an extra '%' must be added to pass the format code through the date/time parser:
It gets really messing in a Windows Bat file where all percent signs must be doubled again (see FAQ #27, My ExifTool command doesn't work from a Windows .BAT file (https://exiftool.org/faq.html#Q27)).
Personally, I try to avoid putting the file percent codes in the date format string. It leads to confusion like this. But in doing so, that means text has to be mixed with tag names, which means the tag name must now have a dollar sign prefix, which can be a different point of confusion.
My version of the command would have been like this, removing the file format codes from the date format string.
exiftool -o . -d '/mnt/synology_foto_backup/User_1/Foto_Backup/%Y-%m-%B/%y-%m-%d %H.%M.%S' '-Filename=/mnt/synology_foto_backup/User_1/Foto_Backup/No_Create_Dates/%f%-2c.%e' '-filename<$DateCreated%+2nc.%e' '-filename<$CreateDate%+2nc.%e' /mnt/synology_homes/User_1/Foto_NyaEither way works, so it's just a question of which style you prefer.