Extract original time and date data from part of filename

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

Previous topic - Next topic

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
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype