-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
74 lines (68 loc) · 2.89 KB
/
Program.cs
File metadata and controls
74 lines (68 loc) · 2.89 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
using System;
using System.IO;
using System.Collections;
using WMPLib;
namespace Duration
{
class Program
{
static WindowsMediaPlayer wmp = new WindowsMediaPlayerClass();
static void Main(string[] args)
{
System.Console.WriteLine("\n");
try
{
TimeSpan total = DirectoryTreeTotalMediaDuration(args[0]);
Console.ForegroundColor = ConsoleColor.Green;
System.Console.WriteLine($"\nTotal media duration of tree is : {total.Days * 24 + total.Hours}:{total.Minutes}:{total.Seconds}");
if (total.TotalHours > 24) System.Console.WriteLine($"\nSomething about : {total.TotalDays} days");
Console.ForegroundColor = ConsoleColor.Gray;
}
catch (IOException e) { }
System.Console.WriteLine("\n");
}
static TimeSpan DirectoryTreeTotalMediaDuration(string path)
{
TimeSpan duration = new TimeSpan(0, 0, 0);
try
{
IEnumerator localDirectories = Directory.EnumerateDirectories(path).GetEnumerator();
IEnumerator files;
System.Console.WriteLine(path);
files=Directory.EnumerateFiles(path).GetEnumerator();
while (files.MoveNext())
{
int fileLength = (int)wmp.newMedia(files.Current.ToString()).duration;
TimeSpan fileLengthspan = new TimeSpan(0, 0, fileLength);
duration = duration + fileLengthspan;
}
while (localDirectories.MoveNext())
{
duration = duration + DirectoryTreeTotalMediaDuration(localDirectories.Current.ToString());
files = Directory.EnumerateFiles(localDirectories.Current.ToString()).GetEnumerator();
System.Console.WriteLine(localDirectories.Current.ToString());
while (files.MoveNext())
{
int fileLength = (int)wmp.newMedia(files.Current.ToString()).duration;
TimeSpan fileLengthspan = new TimeSpan(0, 0, fileLength);
duration = duration + fileLengthspan;
}
}
}
catch (IOException e)
{
Console.ForegroundColor = ConsoleColor.Red;
System.Console.WriteLine(e.Message);
System.Console.WriteLine("\nPlease enter a valid Directory dont ends with \"\\\"");
Console.ForegroundColor = ConsoleColor.Gray;
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
System.Console.WriteLine(e.Message);
Console.ForegroundColor = ConsoleColor.Gray;
}
return duration;
}
}
}