Philip Newton (pne) wrote,
Philip Newton
pne

Using exiftool to modify PDF file timestamps

I generally like to have my file timestamps represent the real date of last modification, rather than the time at which I acquired the file.

To that end, for example, I generally try to download files using a method that preserves the file’s timestamp (such as using GetRight or curl rather than my browser).

However, sometimes I do use the browser, or I get the file from a source which had not preserved the file’s timestamp itself.

With PDF files, though, I find that most of them have a modification timestamp in the file’s metadata itself (and those that don’t often have at least a creation timestamp). So I occasionally update file timestamps based on that timestamp saved inside the file.

I used to do that manually, by looking at the “PDF” tab of the file’s properties and then modifying the file’s timestamp in my file manager.

But then I found that I could use Phil Harvey’s exiftool to do so.

Exiftool was designed to work with EXIF metadata in images, as the name suggests, but it can read (and sometimes write) metadata from other file formats as well, such as PDF, MP3, and others.

So I found I could use it to copy the metadata modification time to the filesystem modification time, with an invocation something like this:

perl -S exiftool "-FileModifyDate<ModifyDate" *.pdf

(Depending on how you installed it, the perl -S exiftool bit might be merely exiftool.)

The operative bit is the "-FileModifyDate<ModifyDate" bit (in double quotes due to the presence of <, which would otherwise have a special meaning): it copies the “modify date” metadata field to the file’s modification date. (If the PDF file has no modification date but does have a creation date, then use CreateDate instead of ModifyDate.)

And presto! All PDF files in the directory have “proper” modification dates.

Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments