static void Main(string[] args) { //arg1 path to picasa data var dbPath = ""; //arg2 path to picasa albums var albumPath = ""; //arg3 path to move the data to var destPath = ""; //arg4 original data path (optional, use if data has been moved from original location) var origPath = ""; if (args.Length < 3) { Console.Write(@" Picture Project photo exporter by Raggles Usage: HC.PP2Picasa.exe dbPath albumPath destPath [origPath] Where dbPath - Path to the Picture Project Databases, normally %USERPROFILEDIR%\AppData\Nikon\PictureProjectData\Database albumPath - Path to the Picture Project albums, notmally %USERPROFILEDIR%\My Pictures\Picture Project destPath - Path to move the images to origPath - Original path to the picture project (as in the database), if you have manually moved the images (optional) "); Environment.Exit(1); } dbPath = args[0]; albumPath = args[1]; destPath = args[2]; if (args.Length > 3) { origPath = args[3]; } else { origPath = albumPath; } OleDbConnection co = new OleDbConnection(String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Database Password=Nikon", String.Format("{0}\\Node.mdb", dbPath))); OleDbCommand cmd = new OleDbCommand("SELECT IDLo, Name, ParentIDLo FROM NodeTable"); cmd.Connection = co; co.Open(); OleDbDataReader reader = cmd.ExecuteReader(); List<PPAlbumData> nodes1 = new List<PPAlbumData>(); List<PPAlbumData> nodes2 = new List<PPAlbumData>(); //read all the nodes into both lists while (reader.Read()) { PPAlbumData data = new PPAlbumData() { ID = reader.GetInt32(0), Name = reader.GetString(1), Parent = reader.GetInt32(2), IDString = reader.GetInt32(0).ToString().PadLeft(4,'0') }; nodes1.Add(data); nodes2.Add(data); } //use the first list to create the directories PPAlbumData root = nodes1.Find(m => m.Name == "root"); nodes1.Remove(root); //create the new directory structure CreateDirectories(nodes1, root, albumPath, destPath); //now find all the images, join on the other tables so we can associate each image to a directory cmd = new OleDbCommand(String.Format("SELECT NodeTable.Name, NodeTable.IDLo, SourceTable.Path FROM ([MS Access;PWD=Nikon;DATABASE={0}\\Item.mdb].ItemTable INNER JOIN [MS Access;PWD=Nikon;DATABASE={0}\\Source.mdb].SourceTable ON SourceTable.IDLo = ItemTable.SourceIDLo) inner join NodeTable on NodeTable.IDLo = ItemTable.ParentIDLo;", dbPath)); cmd.Connection = co; //read all the images into a list List<PPImgData> images = new List<PPImgData>(); reader = cmd.ExecuteReader(); while (reader.Read()) { images.Add(new PPImgData() { ID = reader.GetInt32(1), Path = reader.GetString(2).Replace(origPath, albumPath) }); } co.Close(); //now move all the images to the newly created directories foreach (var node in nodes2) { List<PPImgData> items = images.FindAll(m => m.ID == node.ID); foreach (var item in items) { try { File.Move(item.Path, Path.Combine(node.NewPath, Path.GetFileName(item.Path))); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
static void CreateDirectories(List<PPAlbumData> nodes, PPAlbumData parent, string albumPath, string currentPath) { while (nodes.Find(m => m.Parent == parent.ID) != null) { PPAlbumData node = nodes.Find(m => m.Parent == parent.ID); try { node.NewPath= string.Format("{0}\\{1}", currentPath, node.Name); Directory.CreateDirectory(node.NewPath); CreateDirectories(nodes, node, albumPath, node.NewPath); nodes.Remove(node); } catch (Exception ex) { Console.WriteLine(ex.Message); nodes.Remove(node); } } }