Hi all,
i need to set CreateDate and ModifyDate of a many PDFs to the mtime of each particular file.
I must preserve the timestamp of the files.
I tried this:
#!/usr/bin/env perl use strict; use warnings; use POSIX qw (strftime); use Path::Iterator::Rule; use Image::ExifTool; my $dir = q(./pdf); my $tz = strftime( "%z", localtime() ); # my $tz = strftime( "%z", gmtime() ); $tz =~ s/(\d{2})$/':$1'/; my $rule = Path::Iterator::Rule->new; # $rule->file('*.pdf'); # :-( $rule->file->name(qr/.+\.pdf/); $rule->max_depth(1); my $next = $rule->iter($dir); while ( defined( my $file = $next->() ) ) { my $mtime = ( stat($file) )[9]; my $atime = ( stat($file) )[8]; my ( $m_sec, $m_min, $m_hour, $m_day, $m_month, $m_year ) = ( localtime($mtime) )[ 0, 1, 2, 3, 4, 5 ]; # ( gmtime($mtime) )[ 0, 1, 2, 3, 4, 5 ]; $m_year += 1900; my $m_timestamp = sprintf( "%4d:%02d:%02d %02d:%02d:%02d", $m_year, $m_month, $m_day, $m_hour, $m_min, $m_sec ); $m_timestamp .= $tz; my $exifTool = Image::ExifTool->new(); $exifTool->SetNewValue( "ModifyDate", $m_timestamp ); $exifTool->SetNewValue( "CreateDate", $m_timestamp ); $exifTool->WriteInfo($file); utime $atime, $mtime, $file; } __END__
This ends so:
karls-mac-mini:monks karl$ perl -MImage::ExifTool=:Public -E 'say Imag +eInfo("./pdf/a.pdf")->{CreateDate};' 2015:01:07 14:46:51 karls-mac-mini:monks karl$ ls -hl ./pdf/a.pdf -rw-r--r-- 1 karl karl 48K 7 Feb 14:46 ./pdf/a.pdf
I guess this is one month off target.
What do i miss?
Update: Reset state to [UNSOLVED]
Update 2: It seems like this works:
#!/usr/bin/env perl use strict; use warnings; use POSIX qw (strftime); use Path::Iterator::Rule; use Image::ExifTool; my $dir = q(./pdf); my $rule = Path::Iterator::Rule->new; # $rule->file('*.pdf'); # :-( $rule->file->name(qr/.+\.pdf/); $rule->max_depth(1); my $next = $rule->iter($dir); while ( defined( my $file = $next->() ) ) { my $mtime = ( stat($file) )[9]; my $atime = ( stat($file) )[8]; my $m_timestamp = strftime( "%Y:%m:%d %H:%M:%S%z", localtime($mtim +e) ); my $exifTool = Image::ExifTool->new(); + $exifTool->SetNewValue( "ModifyDate", $m_timestamp ); $exifTool->SetNewValue( "CreateDate", $m_timestamp ); $exifTool->WriteInfo($file); utime $atime, $mtime, $file; } __END__
Edit: Fixed wrong rules.
Update 3: Set state to SOLVED again.
Thank you very much for any hint and best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
In reply to How To Modify PDF Metadata [SOLVED] by karlgoethebier
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |