Created
July 25, 2010 10:45
-
-
Save chaliy/489481 to your computer and use it in GitHub Desktop.
Copy photo files by EXIF infromation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "WindowsBase.dll" | |
#r "PresentationCore.dll" | |
#r "System.Xaml.dll" | |
(* | |
Script to copy all photos from flash card to | |
some folder in form of /Year/Month/Day of the DateTaken | |
DateTaken is retrieved from EXIF infroamtion. | |
To make this script work, you have ensure that all | |
applicable WIC codecs are installed. For example | |
Nicon RAW (NEF) could be downloaded from http://nikonimglib.com/nefcodec/ | |
To run this script you need F# installed. After that you can | |
execute it with | |
> fsi catalogue_photos.fsx | |
or from context menu Run with F# Interactive | |
*) | |
open System | |
open System.IO | |
open System.Windows.Media.Imaging | |
let getDateTaken (u : Uri) = | |
let decoder = BitmapDecoder.Create(u, BitmapCreateOptions.None, BitmapCacheOption.None) | |
let source = decoder.Frames.[0] | |
let meta = source.Metadata :?> BitmapMetadata | |
DateTime.Parse(meta.DateTaken) | |
let sourceFiles = | |
let dir = new System.IO.DirectoryInfo(@"I:\DCIM\100ND40X\") // Path to flash card | |
dir.EnumerateFiles("*.*", System.IO.SearchOption.AllDirectories) | |
|> Seq.filter(fun f -> f.Extension.ToLower() = ".nef" | |
|| f.Extension.ToLower() = ".jpg" ) | |
let makeDestinationPath destBase (inp : FileInfo) = | |
let uri = Uri(inp.FullName) | |
let dateTaken = getDateTaken uri | |
let datePart = dateTaken.ToString("yyyy'/'MM'/'dd").Replace("/", "\\") + "\\" | |
let folderPath = Path.Combine(destBase, datePart) | |
Path.Combine(folderPath, inp.Name) | |
let copyFile (inp : FileInfo) destinationBase = | |
let destination = makeDestinationPath destinationBase inp | |
if File.Exists(destination) = false then | |
Directory.CreateDirectory(Path.GetDirectoryName(destination)) |> ignore | |
printfn "Copy %s" destination | |
inp.CopyTo(destination) |> ignore | |
for inp in sourceFiles do | |
printfn "Processing %s" inp.Name | |
copyFile inp @"C:\Users\M\Pictures\Our\" // Path #1 where to copy | |
copyFile inp @"\\storage\Public\Pictures\" // Path #2 where to copy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment