Extract original time and date data from part of filename

Started by charlars, March 31, 2015, 09:39:03 PM

Previous topic - Next topic

charlars

Hi

I've a problem with Dropbox modifying the original date and time of files, and I've stumbled upon ExifTool, but as a newcomer it can be very difficult indeed to use. I've installed the GUI by Bogdan and have tried to manipulate a file back to how, I would like it - but without any success.

This is my scenario:

I have a file with a FileModifyDate, FileAccessDate and FileCreateDate modified by Dropbox to a date/time when the file was placed in Dropbox.

FileModifyDate   2015:03:31 18:15:32+02:00
FileAccessDate   2015:03:31 18:15:19+02:00
FileCreateDate   2015:03:31 18:15:19+02:00

Apparently it had no DateTimeoriginal.
That is, now I have given it one by copying from the FileModifyDate by using the command I found in a newbies thread:
exiftool -P -ext jpg -if "not $DateTimeOriginal"   "-DateTimeOriginal<FileModifyDate"  Q*

The filename is now (Billede is danish for picture):
Billede 31-03-15 14.18.43.jpg  (i.e. Billede DD-MM-YY HH.MM.SS.jpg)

The filename contains the original date and time. Now I would like to do three things:
1) Change the filename to 2015-03-31 14.18.43.jpg (i.e. CCYY-MM-DD HH.MM.SS.jpg)
2) Ensure that FileCreateDate (and preferably the FileModifyDate and FileAccessDate too) are changed back to the original.
3) Ensure that DateTimeOriginal is changed back to the original. (Most of the files do not even have the same date as the right one in the filename).

I tried this to change the filename:
"-FileName<20%2.14f-%2.11f-%2.8f-%8.17f.jpg"
"-FileName=20%2.14f-%2.11f-%2.8f-%8.17f.jpg"

But with the same results:
Error: File not found - 31-03-15
Error: File not found - 14.18.43.jpg

So it looks like it interprets the file as two files??

There must be a very easy way to do this for an experienced ExifTool user?
Any help would be very much appreciated.

Hayo Baan

Please note that the File*Date information is information from the file system, not from the file itself. They say something about the file, not its content, this is also why these fields changed when you used Dropbox.

  • FileCreateDate is the moment when the file was created on the file system, this can be very different from when the file content was actually created (e.g., when the image was taken)
  • FileModifyDate is the moment when you last saved the file (e.g., after editing it in Photoshop and saving it)
  • FileAccessDate is the moment you last "opened" the file (i.e. some program accessed the content of the file)

From above explanation (and your use of Dropbox) you can already see these fields can change for file system reasons, without you knowing it! I would actually advise (strongly) against relying on them. The only thing you can rely on are metadata tags inside the file. DateTimeOriginal is such a tag. So your first step in adding it if it isn't there already, is a good one.

Now for your questions...

  • If you have the date you want in the filename in the DateTimeOriginal tag, this can most easily be achieved as follows: exiftool "-FileName<$DateTimeOriginal.%e" -d "%Y-%m-%d %H.%M.%S" files. The -d flag formats the datetime the way you specified, the %e is to preserve the extension.
  • Though I would actually advise against this for reasons I stated above, you can achieve this (on windows) like so: exiftool "-FileCreateDate<$DateTimeOriginal" "-FileAccessDate<$DateTimeOriginal" "-FileModifyDate<$DateTimeOriginal" files
  • I'm not sure what you mean here? What original datetimeoriginal are you refering to?

Regarding your last question, if filenames contain spaces (like in your case), you need to properly quote them on the command-line. e.g.: exiftool "-FileName=20%2.14f-%2.11f-%2.8f-%8.17f.jpg" "Billede 31-03-15 14.18.43.jpg"

Note quoting on the windows command-line can be quite tricky sometimes (your cases are quite straightforward though).

Hope this helps,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl

charlars

Thank you for the reply Hayo.

I've tried your suggested command in the GUI, but without success. Please see below for a hopefully elaborated description of my challenge.

I've seen the answer for question 1) in another thread, and I can probably use it, when I've finished the part regarding the 3rd question.
I understand your answer to the second question. I was aware of the difference, and it is not at all important for me either, so I will drop that part.

Now regarding my third question:
With the original date and time, I mean what date and time a given picture is actually taken. (In my case it is very often ipad in-app features saving pictures for the photo roll, when my daughter makes creative stuff from different apps). Somehow this information is apparently lost, when Dropbox takes over. But the information is at least preserved as part of the filename created by Dropbox. That is the reason, why I would like to create and save the DateTimeOriginal from part of the filename. I'm not satisfied with the modification date for that purpose. I only tried that in order to get something in the tag.

So it is the other way round. I do not have the right data (in fact no data at all) in the DateTimeOriginal tag, but in the filename itself, and I want to make the DateTimeOriginal tag from part of the filename + modify the filename by getting rid of the prefix "Billede" and by changing the format of the date and time.

So to sum it up:
How do I create a DateTimeOriginal from a filename like "Billede 31-03-15 14.18.43.jpg" (i.e. Billede DD-MM-YY HH.MM.SS.jpg). Please notice that I will have to add the century manually as part of the command. I need a solution where I can use the command for a whole directory. I have hundreds if not thousands of files this way (pictures prefixed with "Billede" and videos prefixed with "Video" and with the date and time as specified above), so it is not really an option to type the filename for each file. But I guess, that if I use the GUI, I will only need to be in the right folder. When I have the DateTimeOriginal in place, I can probably change the filename with the use of exiftool "-FileName<$DateTimeOriginal.%e" -d "%Y-%m-%d %H.%M.%S" files  as you suggest.

Look forward to hear from you again.

Phil Harvey

Your command will work on any number of files.  Just specify the directory instead of the file name to process all files in a directory.

I recommend writing "TestName" instead of "FileName" first to test your command before you actually rename the files.

The procedure is:

1) Type this in the cmd.exe window: exiftool "-TestName=20%2.14f-%2.11f-%2.8f %8.17f.jpg"

2) Press SPACE.

3) Drag and drop the folder you want to process onto the cmd.exe window.

4) Select the cmd.exe window, then press RETURN.

Using TestName will show you the file names before and after, but will not actually rename the files.  Change TestName to FileName and repeat the procedure to rename the files.  Once the files are renamed to this form, setting DateTimeOriginal from the file name is trivial ("-datetimeoriginal<filename").

Note that you must have ExifTool installed for command-line use to run the command like this without specifying a path for exiftool.   See the install instructions for details.

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

charlars

Thank you both Hayo and Phil for the quick replies. :)

It did work for me now using the direct cmd.exe for the purpose.  :)
Maybe I did a mistake, when I used the GUI. At least I can see, that I was on the right path syntax-wise.  :P

Now I look forward to get on with the whole directory, so I can release some space in my ipad.

Once again thank you very much and what a splendid tool Phil!
I will soon try to investigate somewhat deeper in the facilities offered.

By for now.


zerno

  Dear All,

  I have a very similar issue. There are ~900 photos received by WhatsApp since 2013, and occasionally a CreatedDate ( and ModifiedDate as well) of them all changed to one value - 12 April 2014.
 
  Now it is not useful to sort images by date/time, so I need to extract date from part of a filename, while preserving the original filename so that the WA can see it it file system..

  All files' titles look like IMG-20130223-WA0016.JPG. Year=2013, Month=02, Day=23. 0016 is just an index of image..

  What is the solution??

  Thanks all!

Phil Harvey

This may be done from the command line, but it is a bit tricky.  You would need to use the advanced formatting feature to isolate the date, then add a made-up time (eg. "000000").  It would be better to get the date/time from EXIF metadata if it exists (eg. DateTimeOriginal), rather than the FileName.  But if you must you the FileName, a command like this may do what you want:

exiftool "-filemodifydate<${filename;s/.*?(\d{6}).*//}000000" "-filecreatedate<${filename;s/.*?(\d{6}).*//}000000" DIR

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

zerno

Quote from: Phil Harvey on April 25, 2015, 10:09:22 AM
exiftool "-filemodifydate<${filename;s/.*?(\d{6}).*//}000000" "-filecreatedate<${filename;s/.*?(\d{6}).*//}000000" DIR

- Phil

Very interesting! I tried the command command above on one of my files and got a warning output:
Warning: No writable tags set from IMG-20140101-WA0000.JPG
    0 image files updated
    1 image files unchanged


From this https://exiftool.org/forum/index.php?topic=5912.0 thread I learned, that no writable tags set from FILE warning occurs whern either a tag doesn't exit at all or the tag is composite.

A command exiftool -time:all -s IMG-20140101-WA0000.JPG results in this output:
FileModifyDate                  : 2015:04:19 21:08:42+03:00
FileAccessDate                  : 2015:04:26 21:31:50+03:00
FileCreateDate                  : 2015:04:26 21:31:50+03:00

So ok, three time tags in this file, all belong to [FILE] tags group.

If the time tags exist already, although they are composite, how do I assign a filename to FileCreateDate tag?

I tried first replacing [FILE] time tags in Phil's command with JPEG's or IPTC's tags like DateCreated (or whatsoever), but it didn't work too and showed something like this: No encoding specified
:(

I have a feeling I am near the solution, but can't see obvious things  :o

Phil Harvey

We're not using Composite tags here, so that isn't the problem.

No writable tags will be set if the source tags don't exist (but in this case, the source is FileName which always exists), or if the formatting for the destination tag is incorrect (but in this case you should get an "invalid date/time" warning).  So two other possibilities are:

1) You are using an old version of exiftool.

or

2) you are using the wrong quotes around the command-line arguments (the quoting I used was for Windows).

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

zerno

Phil, I use the latest EXIFTool and Win7 x64.

I found a solution!

1. Assign date and time from filename to datetimoriginal:

exiftool "-datetimeoriginal<filename" DIR

For IMG-20130223-WA0016.JPG 1st step would give:
DateTimeOriginal                : 2014:12:12 00:01:00

2. Then just copy datetimeoriginal to filemodifydate:

exiftool "-filemodifydate<datetimeoriginal" DIR

In my case there were WA0060, WA0061, WA0062 and so on among all files' names, and the first step wrote invalid value to time part (minutes=60,61,62..) of datetimeoriginal and these files weren't succesfully processed during the second step. So after the 1st step I manually assigned valid minutes value to these files and only after that came to the 2nd step. assum. time value is not important (eg. a sunlight noon photo with time=00:14:00)

For me, this worked :)

Phil Harvey

Let me understand.  This worked:

exiftool "-datetimeoriginal<filename" DIR

but this doesn't?:

exiftool "-filemodifydate<filename" DIR

?

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

zerno

I tried it.

But I got 'No writable tags' warning message.

In my post above I mentioned 'datatimeoriginal<filename' to recognize time value in some files' titles as 60+ minutes. And these files couldn't be processed further. I guess 'No writable tags' message appeared thanks to these  problem files. Why do I think so?

When I tried to perfrom the same operation in some GUI version, I got not 'No tags found' message, but an error window clearle said that 'minutes value out of 0..59 range'

Phil Harvey

Quote from: zerno on April 30, 2015, 06:17:55 PM
But I got 'No writable tags' warning message.

For both commands I hope.

If so, then there are only 4 possibilities:

1) the filename couldn't be parsed into a valid date/time (see FAQ 5 for more details).

2) you typed something wrong

3) you are using a very old version of exiftool

4) your ExifTool installation is corrupt somehow

The "minutes value of of range" error is problem 1) above.

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

mdnqsp

Hi everyone,

I know this topic has been idle for a long time, but I just joined the forum and have a similar challenge.

My whatsapp image files are mixed with other pictures (i.e. same folders), and I want to add part of the filename to the Date/time tags.

The files are named IMG-YYYYMMDD-WANNNNNN.JPG

For me the command   exiftool "-alldates<filename"  works perfectly. As described in a previous post, the numbers succeeding WA get converted into time and this is not a problem.

IMG-20160101-WA000013 gets tagged with 'Taken on 01/01/2016 at 00:00:13" - great, I just wanted the date.

But now I want to do it recursively in all sub directories but only for files starting with IMG*

When I try  1)  exiftool -r "-alldates<filename"   ... I get the recursive option working
When I try  2)  exiftool "-alldates<filename"  C:\Images\IMG*.*  ... I get only files starting with IMG being affected

But if I try

exiftool -r "-alldates<filename" C:\Images\IMG*.*

... the recursive option doesn't work, because I am deliberatly selecting the folder, so it doesn't go into sub-directories

I think I need to filter the filename using the 'processing control' option "-if" but I don't know the syntax. I've already tried something like:

exiftool -r "-alldates<filename" -if '$filename "IMG*.*"' C:\Images

But it didn't work. Any suggestions?

Thanks!

Phil Harvey

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

mdnqsp

Worked perfectly!!

Thanks, and congratulations on developing such a helpful tool.

bmn

Hi,

I have a "simple" question, it is possible to ignore a part in the Filename for writing in Exif, with exiftool "-alldates <filename", only the date and NOT time (nothing or 00:00:00 is the same) ?

In the WhatsApp IMG files I'd like to ignore the part in red: IMG-yyyyMMdd-WA0000.

Thanks.

Manolo

Phil Harvey

Hi Manalo,

Try this:

exiftool "-alldates<${filename;$_=substr($_,0,12)} 00:00:00" DIR

This will truncate the file name to 12 characters so numbers after the date don't get interpreted as times, then adds a time of 00:00:00.

It is possible to write nothing for the time, but it isn't common, and some apps may not like it.  And the syntax for this is different for different metadata formats, so to be more specific I would have to know exactly what you want to write.

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

bmn

Hi Phil,

many thanks for your fast answer, for my "problem" these string is perfect because exiftool "-alldates <filename" don't works fine with the WhatsApp WA0060, WA0061, WA0062... files.
If Date taken is missing in Properties > Details the files will don't change. I've try, if is not a my mistake...

Thanks again and great job with ExifTool...

Manolo

bmn

Sorry Phil, just last question...

if is correct, with exiftool -creatortool= FILE (DIR is possible?) I can delete the Program name, but if I want to delete ONLY Google and Picasa like a "Program name" and to keep the others?

Many many thanks.

Manolo

Phil Harvey

Hi Manolo,

You can do this:

exiftool -creatortool-="Google" -creatortool-="Picasa" DIR

But the strings must be an exact match for the tag to be deleted.

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

bmn

Ok Phil,

for Program name (in italian, Nome programma) the correct String is Software so:

exiftool -software-="Google" -software-="Picasa" DIR

Thanks a lot for your time and work...  ;)

Manolo

banelinde

Hello Phil.


Besides all the information's that you had supplied users with, I can't solve following:

From the filename with non-standard date format in the name itself, I want to create DateTimeOriginal.

So, the file is called  IMG-22.03.2017.jpg  or  picture_15.04.2017 15-45h.jpg
and I would like to have an Syntax format to freely choose which part of the name is Year, Month and Day,
and Hours, Minutes, Seconds (alternatively I can use the "000000" principle for time).

So, that Windows command could be something like this:

Exiftool "-datetimeoriginal<${filename characters 10-14 for Year, characters 8-9 for Month, characters 6-7 for Day}121500" *.jpg


Can you give me an clue ?

Kind regards.
Banelinde

Phil Harvey

Hi Banelinde,

There are lots of ways to do this, but one quick way is to pull out all the numbers and arrange them in the proper order.  Something like this perhaps?:

Exiftool "-datetimeoriginal<${filename;$_=join ':',(/\d+/g)[2,1,0]} 12:15:00" -ext jpg .

This should work as long as the first 3 numbers in the file name are day, month, year in that order.

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

banelinde

#24
Hello Phil again.

Your suggestion works perfectly.
And I understood the syntax in the most part, which is related to the RegEx:  \d+ means find digit one or more occurrences
and the 2, 1, 0 are the position of group of digits, found from the left of the file name (this is for other users that are reading this).

So, I can add 3, 4, 5 for the hours, minutes and second, but to keep in mind the official ExIF date coding order.


But, there can be names IMG 12062003 17-15.jpg or IMG 16h 06-12-2003.jpg or 2003 dec 06 15min 17h picture.jpg

So, in case that one of those examples is the case for group of files, can I have the syntax that will explicitly designate character positions
for the Year, Month,Day, Hour, Minute, Seconds.
This is specially necessary for the first file name example, where the full date is one number without breakpoints.
This would also apply if the time would be noted as 121500

Something like:
Exiftool "-datetimeoriginal<${filename;$_=join ':',(character positions for year, month, day,hour,minute,sec)}" *.jpg

Alternatively is something like this possible:
Exiftool "-datetimeoriginal<${filename;$_=join ':',(character positions for year, month, day,hour,minute,sec) IF NO TIME FOUND THEN ENTER 12:15:00}" *.jpg

Is even larger syntax possible like above with addition:
IF NO SECONDS THEN enter character for HH:MM and add "00"


Kind regards.
Banelinde

Phil Harvey

#25
Hi Banelinde,

Yes, you figured out basically how my command worked.  To explain more:

(/\d+/g) generates an array of all strings of digits in the file name

[2,1,0] selects elements 2, 1, 0 from this array

And yes, you can add more elements for the hour, minute seconds if they exist.

The real problem is that you don't have a consistent file naming convention.  One way to deal with this is to have a separate command for each format file name, and add a -if statement that only matches that format of name.  For example:

exiftool -if "$filename =~ /^IMG-\d{2}\.d{2}\.\d{4}\.jpg/i" "-datetimeoriginal<${filename;$_=join ':',(/\d+/g)[2,1,0]} 12:15:00" -ext jpg .

But I think we may be getting beyond your Perl capabilities and/or beyond my limit on how much I want to help you with this...

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

banelinde

Hi Phil.

Thanks!
No need to take more time for my topic.

Just to note, for the file example IMG 12062003 17-15.jpg the IF statement syntax didn't work for me.
I think you also missed an additional double quote after the /i.
I didn't got the differences between the different dot (.) positions within the IF statement.

My solution for the most cases and for the uncertainty if the name contains TIME characters is:
Exiftool "-datetimeoriginal<${filename;$_=join ':',(/\d+/g)[2,1,0,3,4,5]} 00" "-overwrite_original" *.jpg

Kind regards.
Banelinde

Phil Harvey

Hi Banelinde,

Quote from: banelinde on April 12, 2018, 11:19:11 AM
I think you also missed an additional double quote after the /i.

Thanks.  I've fixed this in my post.

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

tonylost

Hi!

I'm trying to get the date and time data for the exif tag in files with this format:

luxemburgo1591germany1528-20180801-1920.jpg
madrid121spain16125-20180715-0002.jpg
paris12france13429-20170506-0750.jpg
barcelona156spain749-20180801-0015.jpg
lisboa13portugal826-20170606-2323.jpg
berlin06785germany72-20180805-1632.jpg

What parameters should be used for the exiftool tool to ignore the numbers that exist before the first hyphen? This way I could extract date and time of the file name.

Thanks in advance.

StarGeek

You could use ${filename;s/^[^-]*//} and copy that into the tag you want.  See 3rd paragraph of FAQ #5 for details.

The regex in that will delete everything in the filename up to the first hyphen.  As per FAQ #5, exiftool will then use the rest of the numbers as the Date/time.  But take note that you would still be missing the seconds for any date time tag and would probably need to add some numbers to the end (such as 00).

For example
C:\>exiftool -P -overwrite_original "-AllDates<${filename;s/^[^-]*//} 00" "Y:\!temp\luxemburgo1591germany1528-20180801-1920.jpg"
    1 image files updated

C:\>exiftool -g1 -a -s -AllDates "Y:\!temp\luxemburgo1591germany1528-20180801-1920.jpg"
---- IFD0 ----
ModifyDate                      : 2018:08:01 19:20:00
---- ExifIFD ----
DateTimeOriginal                : 2018:08:01 19:20:00
CreateDate                      : 2018:08:01 19:20:00
* 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).