-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generator.cs
61 lines (50 loc) · 1.37 KB
/
Generator.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
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.IO;
namespace FileGenerator;
internal class Generator
{
public int FileCountPerDir { get; set; } = 400;
public int DirLevel { get; set; } = 2;
public int DirCountPerDir { get; set; } = 5;
public int FileMaxSizeBytes { get; set; } = 4_194_304;
public void Generate(string dir)
{
CreateDirIfNeeded(dir);
GenerateDirTree(dir, 0);
}
private void GenerateDirTree(string dir, int level)
{
if (level > DirLevel)
{
return;
}
CreateFiles(dir);
level++;
for (int i = 0; i < DirCountPerDir; i++)
{
var current = Path.Combine(dir, $"dir{i}");
Directory.CreateDirectory(current);
GenerateDirTree(current, level);
}
}
private void CreateFiles(string dir)
{
for (int i = 0; i < FileCountPerDir; i++)
{
var name = Path.Combine(dir, $"file{i}.txt");
Random random = new Random();
var content = new Byte[random.Next(FileMaxSizeBytes)];
random.NextBytes(content);
File.WriteAllBytes(name, content);
Console.WriteLine(name);
}
}
private void CreateDirIfNeeded(string dir)
{
if (Directory.Exists(dir))
{
return;
}
Directory.CreateDirectory(dir);
}
}