Set PDF mtime to ModifyDate, CreateDate fallback, format tolerant

Started by obetz, March 09, 2019, 07:11:39 AM

Previous topic - Next topic

obetz

Hi All,

to set the mtime of PDFs to the "ModifyDate" metadata, I used

exiftool "-filemodifydate<PDF:ModifyDate" *.pdf

Most times this works, but I have to solve two problems:

1. Some PDFs have only "PDF:CreateDate" so I want to use ModifyDate it is available, else CreateDate.

2. Some PDFs don't use ISO8601 date format but e.g. "1/30/2017 00:09:14". Stupid, because there can be ambiguous situations like "1/2/2019 00:09:14". Any idea how to deal with this?

Thanks in advance

Oliver

Phil Harvey

Hi Oliver,

Quote from: obetz on March 09, 2019, 07:11:39 AM
1. Some PDFs have only "PDF:CreateDate" so I want to use ModifyDate it is available, else CreateDate.

exiftool "-filemodifydate<PDF:CreateDate" "-filemodifydate<PDF:ModifyDate" -ext pdf .

Quote2. Some PDFs don't use ISO8601 date format but e.g. "1/30/2017 00:09:14". Stupid, because there can be ambiguous situations like "1/2/2019 00:09:14". Any idea how to deal with this?

Try this:

exiftool "-filemodifydate<${PDF:CreateDate;s[(\d{1,2})/(\d{1,2})/(\d{4})][$3:$1:$2]}" "-filemodifydate<${PDF:ModifyDate;s[(\d{1,2})/(\d{1,2})/(\d{4})][$3:$1:$2]}" -ext pdf .

I don't have time to test this right now, but I am trying to move the year to the start.  But I think the single-digit month may be a problem when writing the date.

- Phil

Edit:  I've tested it now and it seems to work ok.
...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 ($).

obetz

Hi Phil,

you are great, many thanks!

Although I know PCRE (somewhat), I wasn't able to figure out the right replacement syntax. Now I can adapt it for possible future requirements.

Thanks again for exiftool:

Oliver