-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCommandLineFiles.cs
48 lines (45 loc) · 1.38 KB
/
CommandLineFiles.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
40
41
42
43
44
45
46
47
48
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace CLARiNET
{
public static class CommandLineFiles
{
public static string[] FilesCheck(string command, string path, string searchPattern)
{
string[] files = Directory.GetFiles(path, searchPattern, new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive });
if (files.Length > 0)
{
if (files.Length == 1)
{
Console.WriteLine("File name: " + files[0] + "\n");
}
else
{
Console.WriteLine("Found {0:N0} files.\n", files.Length);
Console.WriteLine("First file name: " + files[0] + "\n");
}
}
else
{
if (command.ToEnum<Command>() == Command.CLAR_DOWNLOAD)
{
if (!Directory.Exists(path))
{
throw new Exception("Directory does not exist.");
}
}
else
{
throw new Exception("No files found.");
}
}
return files;
}
}
}