| 
					
				 | 
			
			
				@@ -13,76 +13,75 @@ namespace PhotoSorter 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         static void Main(string[] args) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            string postfix = "Hansi"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Console.WriteLine("This application can sort photos in CURRENT and sub directory by EXIF shotdate Or it's Filename, move the photos to a NEW sub-Directory which created by date like \"2017-10-01\". Hansi 2017-10-21"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Console.WriteLine("This application can sort photos in CURRENT directory by EXIF shotdate Or it's Filename, move the photos to a NEW sub-Directory which created by date like \"2017-10-01\". Hansi 2017-10-21"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Console.WriteLine("Press any key to DO it..."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Console.ReadKey(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             string folderIn = AppDomain.CurrentDomain.BaseDirectory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //int hourOffset = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //int monthOffset = -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var files = Directory.GetFiles(folderIn, "*.jpg", SearchOption.AllDirectories); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            int k = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Console.WriteLine("Total:" + files.Length.ToString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            foreach (var file in files) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            string[] extArray = new string[] {".jpg",".dng",".nef"}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            doWork(folderIn, extArray); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Console.WriteLine("Done!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Console.ReadKey(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        static void doWork(string folderIn,string[] extArr) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (int exti = 0; exti < extArr.Length; exti++) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                k++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                FileInfo fi = new FileInfo(file); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                Console.WriteLine(k.ToString() + "/" + files.Length.ToString() + "\t" + fi.Name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                string newFileName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if ((fi.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Console.WriteLine("---------Working with " + extArr[exti] + " files!--------------"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                var files = Directory.GetFiles(folderIn, "*" + extArr[exti], SearchOption.TopDirectoryOnly); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                int k = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Console.WriteLine("Total:" + files.Length.ToString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                foreach (var file in files) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    var dateTaken = GetDateTakenFromImage(file); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (dateTaken == DateTime.MinValue) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    k++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    FileInfo fi = new FileInfo(file); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    Console.WriteLine(k.ToString() + "/" + files.Length.ToString() + "\t" + fi.Name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    string newFileName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if ((fi.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Console.WriteLine("ignore " + fi.Name + ":Get Exif Fail"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Console.WriteLine("Trying to get Date From filename..."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        dateTaken = GetDateFromImageFileName(file); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        var dateTaken = GetDateTakenFromImage(file); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         if (dateTaken == DateTime.MinValue) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            Console.WriteLine("ignore " + fi.Name + ":Get Date By File Name Fail"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Console.WriteLine("ignore " + fi.Name + ":Get Exif Fail"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Console.WriteLine("Trying to get Date From filename..."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            dateTaken = GetDateFromImageFileName(file); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            if (dateTaken == DateTime.MinValue) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Console.WriteLine("ignore " + fi.Name + ":Get Date By File Name Fail"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (Path.GetExtension(file).ToLower() != ".jpg") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Console.WriteLine("ignore " + fi.Name + "NOT jpg File"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    //dateTaken = dateTaken.AddHours(hourOffset); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    //dateTaken = dateTaken.AddMonths(monthOffset); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //dateTaken = dateTaken.AddHours(hourOffset); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //dateTaken = dateTaken.AddMonths(monthOffset); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    var newDir = Path.Combine(Path.GetDirectoryName(file), dateTaken.ToString("yyyy-MM-dd")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        var newDir = Path.Combine(Path.GetDirectoryName(file), dateTaken.ToString("yyyy-MM-dd")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    newFileName = Path.Combine(newDir, Path.GetFileName(file)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        newFileName = Path.Combine(newDir, Path.GetFileName(file)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!Directory.Exists(Path.GetDirectoryName(newFileName))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Directory.CreateDirectory(Path.GetDirectoryName(newFileName)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (!Directory.Exists(Path.GetDirectoryName(newFileName))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Directory.CreateDirectory(Path.GetDirectoryName(newFileName)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    //newFileName = Path.Combine(Path.GetDirectoryName(file), dateTaken.ToString("yyyy-MM-dd HHmm.ss") + " " + postfix + ".jpg"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //newFileName = Path.Combine(Path.GetDirectoryName(file), dateTaken.ToString("yyyy-MM-dd HHmm.ss") + " " + postfix + ".jpg"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (file != newFileName) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        int i = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        while (File.Exists(newFileName)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (file != newFileName) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            newFileName = Path.Combine(Path.GetDirectoryName(file), dateTaken.ToString("yyyy-MM-dd HHmm.ss") + " " + i++ + " " + postfix + ".jpg"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            int i = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            while (File.Exists(newFileName)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                newFileName = Path.Combine(Path.GetDirectoryName(file), dateTaken.ToString("yyyy-MM-dd HHmm.ss") + " " + i++ + ".jpg"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Debug.Assert(!File.Exists(newFileName)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            File.Move(file, newFileName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Debug.Assert(!File.Exists(newFileName)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        File.Move(file, newFileName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Console.WriteLine("Done!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Console.ReadKey(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// We init this once so that if the function is repeatedly called 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// It isn't stressing the garbage man 
			 |