User Tools

Site Tools


software:datetofile

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
software:datetofile [2012/05/07 03:49] – created adminsoftware:datetofile [2013/02/09 21:34] (current) – [photo sorting - dateTofile] admin
Line 1: Line 1:
-====== dateTofile ====== +====== photo sorting - dateTofile ====== 
-This page describes a perl- and an Applescript which adds the date and time to the leading part of a filename. This can be helpful when merging foots from different cameras into one directoryAn offset can be set to adjust for time differences between cameras.\\ \\ The applescript works just as front end to allow for easy drag and drop.\\ \\ Adding a timestamp in front of the file is done with the perl script.\\ \\ Example 1: Drag and drop the file Img040.jpg onto dateTofile.app (The file Img040 has been created on 11.40.23 on the 23 of March 2012) The file will be renamed to 20120323_114023.Img040.jpg\\ \\ Example 2Drag and drop the file Img040.jpg onto dateTofile+3600.app . The file will be renamed to 20120323_124023.Img040.jpg\\ \\ Example 3Via the terminalthe script can be invoked with ./date2file [-t offset] file1 file2 ... fileN, where [ ] is optional.+This page describes a solution to help organizing files with different creation dates. It is an alternative to the great [[http://www.sno.phy.queensu.ca/~phil/exiftool/|exiftool]]. Practical for merging different series of photos from cameras with different time settings into one directory. By adding the date and time to the leading part of a filename, files can be sorted chronologicallyAdditionally an offset can be applied to the date and time to correct time differences between cameras. The solution consists of perl script which adds the date and time to the filename, controlled by an applescript to allow easy drag and drop functionality from the desktop.\\ \\ To understand the functionality better, take for example the following file: 
 +  * file name: Img002.jpg 
 +  * Creation date23rd of Mai2012, 10.07.49 PM
  
-===== Installation ===== +After selecting the file, drag and drop it onto the applescript. Depending on the offset, the filename will be modified as follows: 
-  - Save the applescript from below to a directory.+ 
 +^  Offset  ^  Original file  ^  After drag and drop  ^  Script name  ^  (internal command) 
 +^ No offset  | Img002.jpg  | 20120523_220749.Img002.jpg  | dateTofile.app  | ./date2file Img002.jpg 
 +^ Offset +1 hr  | Img002.jpg  | 20120523_230749.Img002.jpg  | dateTofile+3600.app  | ./date2file -t +3600 Img002.jpg 
 +^ Offset -1 day  | Img002.jpg  | 20120423_220749.Img002.jpg  | dateTofile-86400.app  | ./date2file -t -86400 Img002.jpg 
 + 
 +When using the script directly via the terminal, the script can be invoked with the following command: 
 +  ./date2file [-t offset] file1 file2 ... fileN 
 +where [ ] is optional.\\ \\ If it is necessary to change the date-time stamp, the script can be run again with the date-time stamped file. Instead of writing an additional date-time stamp, the current one is being replaced instead. This prevents writing double time-stamps like 20120523_230749.20120523_220749.Img002.jpg . For example: 
 +^  Original file  ^  After drag and drop  ^  Offset  ^  Script name  ^  (internal command) 
 +| 20120523_220749.Img002.jpg  | 20120523_240749.Img002.jpg  | +2 hr  | dateTofile+7200.app  | ./date2file -t + 7200 20120523_220749.Img002.jpg 
 +| 20120523_070749.Img002.jpg(((Please note that for calculating the new offset to the leading date-time stamp, still the original file creation date is being used, instead of the current leading date-time stamp.)))  | 20120523_240749.Img002.jpg  | +2 hr  | dateTofile+7200.app  | ./date2file -t + 7200 20120523_070749.Img002.jpg 
 +====== Download ====== 
 +The scripts can be downloaded here: [[http://www.auditeon.com/xyz/dateTofile.app.zip]]. The perl script is already stored in the following directory: 
 +  dateTofile.app/Contents/Resources/ 
 + 
 +====== Manual installation ====== 
 +  - Save the applescript, named dateTofile, from below to a directory.
   - Copy the perl script, named date2file, into the following subdirectory of the applescript directory: %%dateTofile.app/Contents/Resources/%%   - Copy the perl script, named date2file, into the following subdirectory of the applescript directory: %%dateTofile.app/Contents/Resources/%%
-  - make the perl script executable with chmod +x date2file+  - make the perl script executable with:\\  chmod +x date2file
  
 ==== Applescript - dateTofile ==== ==== Applescript - dateTofile ====
Line 96: Line 115:
  
 ==== Perl script - date2file ==== ==== Perl script - date2file ====
 +The script below will add a leading date-time stamp to a filename.
 <code perl>#!/usr/bin/perl <code perl>#!/usr/bin/perl
 use File::Basename; use File::Basename;
 +use File::Spec;
 use Time::Piece; use Time::Piece;
 use File::Copy; use File::Copy;
Line 128: Line 149:
 } }
  
-# open (MYFILE, '>>/Users/iudex/data.txt'); 
-# print MYFILE "Offset in seconds: $offset"."\n"; 
 foreach (@ARGV) { foreach (@ARGV) {
   $file_dirname = dirname($_);   $file_dirname = dirname($_);
-  if ($file_dirname == '.') { # empty directories have a dot. This should be removed!+  if ($file_dirname eq '.') { # empty directories have a dot. This should be removed!
     $file_dirname = '';     $file_dirname = '';
   }   }
Line 141: Line 160:
     if ($file_datepart =~ /^[+-]?\d+$/ ) {     if ($file_datepart =~ /^[+-]?\d+$/ ) {
       if ($file_timepart =~ /^[+-]?\d+$/ ) {       if ($file_timepart =~ /^[+-]?\d+$/ ) {
-        if (substr($file_basename, 8,1) == '_') { +        if (substr($file_basename, 8,1) eq '_') { 
-          if (substr($file_basename,15,1) == '.') {+          if (substr($file_basename,15,1) eq '.') {
             # is already in date format;             # is already in date format;
             $file_basename = substr($file_basename,16);             $file_basename = substr($file_basename,16);
Line 153: Line 172:
   $fdate = localtime($file_time)->ymd(''); #yyyymmdd format   $fdate = localtime($file_time)->ymd(''); #yyyymmdd format
   $ftime = localtime($file_time)->hms(''); #hhmmss 24 hours format   $ftime = localtime($file_time)->hms(''); #hhmmss 24 hours format
-  $file_target = $file_dirname.$fdate."_".$ftime.".".$file_basename+  $file_target = File::Spec->catfile($file_dirname$fdate."_".$ftime.".".$file_basename);
-#  print  "original: $_"."\n"; +
-#  print $file_target."\n";+
   move($_,$file_target);   move($_,$file_target);
  
 } }
-# close (MYFILE); 
 </code> </code>
software/datetofile.1336355348.txt.gz · Last modified: 2012/05/07 03:49 by admin