-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
37 lines (31 loc) · 880 Bytes
/
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
using System.Text.Json;
using ClearTempFiles;
const string configFile = "files-to-delete.json";
var configPath = $"{AppContext.BaseDirectory}\\{configFile}";
if (File.Exists(configPath))
{
await using (var stream = File.OpenRead(configPath))
{
var config = await JsonSerializer.DeserializeAsync<List<FilesToDelete>>(stream);
if (config == null) throw new Exception("Config not correct");
await Task.WhenAll(config.Select(f => f.ClearFolder()));
return;
}
}
var example = new List<FilesToDelete>
{
new FilesToDelete
{
FileMask = @".*\.zip",
Path = @"C:\temp-zips",
Recurse = false,
RetentionInDays = 2
},
new FilesToDelete
{
Path = @"C:\temp",
Recurse = true
},
};
await File.WriteAllTextAsync(configPath, JsonSerializer.Serialize(example));