Created
October 13, 2013 23:26
-
-
Save jonsagara/6968496 to your computer and use it in GitHub Desktop.
Copy a flat directory of iPhone pictures and videos into a YYYYMM folder structure, based on the date the picture/video was taken.
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
class Program | |
{ | |
private const string SourceDirectory = @"D:\iPhoneMedia"; | |
private const string DestDirectory = @"D:\iPhoneMediaSorted"; | |
static void Main(string[] args) | |
{ | |
var sourceDir = new DirectoryInfo(SourceDirectory); | |
// Group by YYYYMM | |
var yearMonth = sourceDir | |
.GetFiles() | |
.OrderBy(fi => fi.LastWriteTime) | |
.GroupBy(fi => (fi.LastWriteTime.Year * 100) + fi.LastWriteTime.Month) | |
.ToList(); | |
foreach (var ym in yearMonth) | |
{ | |
Console.WriteLine("{0}: {1}", ym.Key, ym.Count()); | |
var destFolder = Path.Combine(DestDirectory, ym.Key.ToString()); | |
if (!Directory.Exists(destFolder)) | |
{ | |
Directory.CreateDirectory(destFolder); | |
} | |
foreach (var fi in ym) | |
{ | |
var destFile = Path.Combine(destFolder, fi.Name); | |
Console.WriteLine("Copying {0} to {1}", fi.Name, destFile); | |
fi.CopyTo(destFile, overwrite: true); | |
} | |
} | |
Console.WriteLine("Press ENTER to quit..."); | |
Console.ReadLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment