-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
39 lines (37 loc) · 1.51 KB
/
Program.cs
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
using System;
using System.IO;
namespace randomFilePicker
{
class Program
{
static void Main(string[] args)
{
string usage = "randomFilePicker path/to/file \"file extension\"";
if (args.Length == 2)
{
string[] filepaths = Directory.GetFiles(@args[0], args[1], SearchOption.AllDirectories);
int numberOfFiles = filepaths.Length;
Random rand = new Random();
int fileTargetNumber = rand.Next(0, numberOfFiles);
string fileTarget = filepaths[fileTargetNumber];
Console.WriteLine($"Opening \"{fileTarget}\"");
using (System.Diagnostics.Process pProcess = new System.Diagnostics.Process())
{
pProcess.StartInfo.FileName = $"{fileTarget}";
pProcess.StartInfo.UseShellExecute = true;
pProcess.StartInfo.RedirectStandardOutput = false;
pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
pProcess.Start();
pProcess.WaitForExit();
Environment.Exit(0);
}
}
else
{
Console.WriteLine("Please Enter a File Path");
Console.WriteLine($"Usage: {usage}");
Environment.Exit(0);
}
}
}
}