-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (47 loc) · 2.42 KB
/
Program.cs
File metadata and controls
71 lines (47 loc) · 2.42 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
namespace TestProject
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
var cacheFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testCacheFile222.txt");
var dir1 = Directory.CreateDirectory("TestFolder333");
var subdir1 = dir1.CreateSubdirectory("SubFolder5555");
// var subdir2 = dir1.CreateSubdirectory("SubFolder3");
// subdir1.CreateSubdirectory("SubsubFolder4");
File.WriteAllText(Path.Combine(dir1.FullName, "AAAASSSSAAA.txt"), "Test content44444444444");
File.WriteAllText(Path.Combine(subdir1.FullName, "Subfile2228822.txt"), "Test content222");
Console.ReadKey();
}
public static List<Tuple<string, DateTime>> GetFilesWithCreateDates(string baseDirectory)
{
List<Tuple<string, DateTime>> result = new List<Tuple<string, DateTime>>();
// Получаем массив путей ко всем файлам в директории и её подпапках
string[] allFiles = Directory.GetFiles(baseDirectory, "*.*", SearchOption.AllDirectories);
for (int i = 0; i < allFiles.Length; i++)
{
string fullFilePath = allFiles[i];
string relativePath = fullFilePath.Substring(baseDirectory.Length);
// Удаляем возможный ведущий символ "/"
if (relativePath.StartsWith("\\\\") || relativePath.StartsWith("/"))
{
relativePath = relativePath.Substring(1);
}
try
{
// Запрашиваем дату создания файла
DateTime creationTimeUtc = File.GetCreationTimeUtc(fullFilePath);
// Добавляем кортеж в результирующий список
Tuple<string, DateTime> tupleItem = new Tuple<string, DateTime>(relativePath, creationTimeUtc);
result.Add(tupleItem);
}
catch (Exception ex)
{
Console.WriteLine("Ошибка при обработке файла " + fullFilePath + ": " + ex.Message);
}
}
return result;
}
}
}