forked from MicrosoftDocs/mslearn-dotnet-files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
36 lines (30 loc) · 1009 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.IO;
using System.Collections.Generic;
//Get specifec File that is inside The funcation
var salesFiles = FindFiles("stores");
foreach (var file in salesFiles)
{
Console.WriteLine(file);
}
//Get current path
Console.WriteLine(Directory.GetCurrentDirectory());
string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
////////////////////////////////////////////////////////////////////////////
Console.WriteLine($"stores{Path.DirectorySeparatorChar}201");
// returns:
// stores\201 on Windows
// stores/201 on macOS
IEnumerable<string> FindFiles(string folderName)
{
List<string> salesFiles = new List<string>();
var foundFiles = Directory.EnumerateFiles(folderName, "*", SearchOption.AllDirectories);
foreach (var file in foundFiles)
{
// The file name will contain the full path, so only check the end of it
if (file.EndsWith("sales.json"))
{
salesFiles.Add(file);
}
}
return salesFiles;
}