This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
software:datetofile [2012/05/07 03:49] – created admin | software:datetofile [2013/02/09 21:34] (current) – [photo sorting - dateTofile] admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 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 directory. An offset can be set to adjust for time differences between cameras.\\ \\ The applescript works just as a 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 2: Drag and drop the file Img040.jpg onto dateTofile+3600.app . The file will be renamed to 20120323_124023.Img040.jpg\\ \\ Example 3: Via the terminal, the 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:// |
+ | * file name: Img002.jpg | ||
+ | * Creation date: 23rd of Mai, 2012, 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 | ||
+ | ^ No offset | ||
+ | ^ Offset +1 hr | Img002.jpg | ||
+ | ^ Offset -1 day | 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 | ||
+ | | 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.))) | ||
+ | ====== Download ====== | ||
+ | The scripts can be downloaded here: [[http:// | ||
+ | dateTofile.app/ | ||
+ | |||
+ | ====== Manual installation | ||
+ | - Save the applescript, named dateTofile, | ||
- Copy the perl script, named date2file, into the following subdirectory of the applescript directory: %%dateTofile.app/ | - Copy the perl script, named date2file, into the following subdirectory of the applescript directory: %%dateTofile.app/ | ||
- | - make the perl script executable with chmod +x date2file | + | - make the perl script executable with: |
==== 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># | <code perl># | ||
use File:: | use File:: | ||
+ | use File::Spec; | ||
use Time:: | use Time:: | ||
use File::Copy; | use File::Copy; | ||
Line 128: | Line 149: | ||
} | } | ||
- | # open (MYFILE, '>>/ | ||
- | # print MYFILE " | ||
foreach (@ARGV) { | foreach (@ARGV) { | ||
$file_dirname = dirname($_); | $file_dirname = dirname($_); | ||
- | if ($file_dirname | + | if ($file_dirname |
$file_dirname = ''; | $file_dirname = ''; | ||
} | } | ||
Line 141: | Line 160: | ||
if ($file_datepart =~ / | if ($file_datepart =~ / | ||
if ($file_timepart =~ / | if ($file_timepart =~ / | ||
- | if (substr($file_basename, | + | if (substr($file_basename, |
- | if (substr($file_basename, | + | if (substr($file_basename, |
# is already in date format; | # is already in date format; | ||
$file_basename = substr($file_basename, | $file_basename = substr($file_basename, | ||
Line 153: | Line 172: | ||
$fdate = localtime($file_time)-> | $fdate = localtime($file_time)-> | ||
$ftime = localtime($file_time)-> | $ftime = localtime($file_time)-> | ||
- | $file_target = $file_dirname.$fdate." | + | $file_target = File:: |
- | # print " | + | |
- | # print $file_target." | + | |
move($_, | move($_, | ||
} | } | ||
- | # close (MYFILE); | ||
</ | </ |