-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
116 lines (100 loc) · 3.9 KB
/
Copy pathProgram.cs
File metadata and controls
116 lines (100 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace LatestModifiedFolders
{
class Program
{
static DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
//static FileInfo FindName(string prefix, string suffix, int num, FileInfo[] files, out string name)
//{
// string match = prefix + num.ToString("000") + suffix;
// foreach (FileInfo file in files)
// {
// if (file.Name.StartsWith(match))
// {
// name = file.Name.Substring(match.Length);
// return file;
// }
// }
// name = null;
// return null;
//}
static DateTime FixFolder(string folder)
{
DirectoryInfo directory = new DirectoryInfo(folder);
DateTime latest = new DateTime(epoch.Ticks);
DirectoryInfo[] directories = directory.GetDirectories("*", SearchOption.TopDirectoryOnly);
foreach (DirectoryInfo child in directories)
{
DateTime stamp = FixFolder(Path.Combine(folder, child.Name));
if (stamp.CompareTo(latest) > 0)
latest = stamp;
}
FileInfo[] files = directory.GetFiles("*", SearchOption.TopDirectoryOnly);
//FileInfo older, newer;
//string title, name;
//for (int num = 1; num <= 500; num++)
//{
// if ((older = FindName("Naruto Shippuden Episode ", " ", num, files, out title)) != null)
// {
// if ((newer = FindName("Naruto Shippuden - ", "", num, files, out name)) != null)
// {
// string label = "Naruto.Shippuden." + num.ToString("000") + "." + title;
// try
// {
// newer.MoveTo(Path.Combine(folder, label));
// older.Delete();
// Console.WriteLine("Relabelled {0} from {1} to {2}", newer.Name, older.Name, label);
// }
// catch (Exception e)
// {
// Console.WriteLine("Died trying {0} from {1} to {2}", newer.Name, older.Name, label);
// throw e;
// }
// }
// }
//}
foreach (FileInfo child in files)
{
// skip Thumbs.db
if (child.Name == "Thumbs.db")
continue;
else if (latest.CompareTo(epoch) <= 0)
latest = child.LastWriteTime;
else if (child.LastWriteTime.CompareTo(latest) > 0)
latest = child.LastWriteTime;
}
// if empty, make sure modified is same as creation
if (latest.CompareTo(epoch) <= 0)
latest = directory.CreationTime;
if (directory.LastWriteTime.CompareTo(latest) > 0)
{
directory.LastWriteTime = latest;
Console.WriteLine("Setting {0} to {1}", folder, latest.ToString());
}
return latest;
}
static void Usage()
{
Console.WriteLine("Usage: {0} folder", Environment.CommandLine);
Environment.Exit(1);
}
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
if (args.Length != 1)
{
Usage();
return;
}
string folder = args[0];
if (!Directory.Exists(folder))
throw new Exception("Folder '" + folder + "' is invalid!");
FixFolder(folder);
Console.WriteLine("Done");
}
}
}