Converting Picasa ini dates to directory dates

One issue I faced in the process of migrating from Picasa to Adobe Lightroom is that Picasa stores event dates in .picasa.ini files. I had spent many hours setting correct dates in my events (folders) and wanted to import them. So I wrote the following C# script (should work for Windows and OS X – I ran in via Mono).

Update: This code is on github @ https://github.com/DavidVeksler/EmbedPicasaProperties

The below will not be updated.

using System;
using System.IO;
 
namespace ConvertPicasaToFolderDates
{
        class MainClass
        {
                private const string IniFileName = @".picasa.ini";
 
                private static void Main(string[] args)
                {
                        string startFolder = @"/Users/davidv/Pictures/";
 
                        Console.WriteLine(startFolder);
 
                        UpdateFoldersInPath(startFolder);
 
                }
 
                private static void UpdateFoldersInPath(string folder)
                {
                        string[] directories = Directory.GetDirectories(folder);
 
                        if (directories.Length > 0)
                                Console.WriteLine("{0} folders in {1}", directories.Length, folder);
 
                        foreach (string directory in directories)
                        {
                                try
                                {
                                        string iniPath = Path.Combine(directory, IniFileName);
 
                                        if (File.Exists(iniPath))
                                        {
                                                Console.WriteLine("Parse " + iniPath);
 
                                                foreach (string line in File.ReadAllLines(iniPath))
                                                {
                                                        // date=29586.603900
                                                        if (!line.StartsWith("date=")) continue;
 
                                                        string dateString = line.Substring(5);
 
                                                        DateTime date = ConverPicasaDateToDateTime(dateString);
 
                                                        DateTime originalTime = Directory.GetCreationTime(directory);
 
                                                        if (originalTime != date && date.Year < 2010)
                                                        {
                                                                Console.WriteLine("{0} to {1}", originalTime, date);
                                                                Directory.SetCreationTime(directory, date);
// (For Mono SetCreationTime did not work correctly, so use SetLastWriteTime.)
                                                                Directory.SetLastWriteTime(directory,date);
                                                        }
 
                                                        break;
                                                }
                                        }
                                }
                                catch (Exception ex)
                                {
                                        Console.WriteLine(ex);
                                }
 
                                try
                                {
                                        UpdateFoldersInPath(directory);
                                }
                                catch (Exception ex)
                                {
                                        Console.WriteLine(ex);
                                }
                        }
                }
 
                // convert =29586.603900 to date time format
                private static DateTime ConverPicasaDateToDateTime(string dateString)
                {
                        var startDate = new DateTime(1900, 1, 1);
 
                        DateTime date = startDate.AddDays(Convert.ToDouble(dateString) -2);
 
                        Console.WriteLine("new date: " + date);
 
                        return date;
                }
        }
}

 

Leave a Reply