Ejemplo n.º 1
0
        public static DateTime GetDateTakenOrModified(FileInfo imageFileInfo)
        {
            DateTime dt = ExifParserLibrary.GetDateTaken(imageFileInfo.FullName);

            if (dt.Equals(DateTime.MinValue))
            {
                dt = imageFileInfo.CreationTime < imageFileInfo.LastWriteTime ? imageFileInfo.CreationTime : imageFileInfo.LastWriteTime;
            }

            return(dt);
        }
Ejemplo n.º 2
0
        public static void MovePicture(FileInfo fi, string destination, bool keepDuplicates)
        {
            DateTime      dt = ExifParserLibrary.GetDateTakenOrModified(fi);
            string        destinationFolder = destination + "\\PicSort_" + dt.Year + "_" + dt.Month.ToString("D2");
            DirectoryInfo di = new DirectoryInfo(destinationFolder);

            if (!di.Exists)
            {
                di.Create();
            }
            FileInfo newFi = new FileInfo(destinationFolder + "\\" + fi.Name);

            if (newFi.Exists)
            {
                if (newFi.Length == fi.Length)
                {
                    // The file already exists
                    if (keepDuplicates)
                    {
                        destinationFolder = destination + "\\PicSort_Garbage";
                        di = new DirectoryInfo(destinationFolder);
                        if (!di.Exists)
                        {
                            di.Create();
                        }
                        newFi = new FileInfo(destinationFolder + "\\" + fi.Name);
                        if (newFi.Exists)
                        {
                            RenameAndMove(fi, newFi);
                        }
                        else
                        {
                            fi.CopyTo(newFi.FullName);
                        }
                    }
                    else
                    {
                        fi.Delete();
                    }
                }
                else
                {
                    RenameAndMove(fi, newFi);
                }
            }
            else
            {
                fi.CopyTo(newFi.FullName);
            }
            fi.Delete();
        }