-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalFileHelper.cs
More file actions
41 lines (38 loc) · 1.27 KB
/
Copy pathLocalFileHelper.cs
File metadata and controls
41 lines (38 loc) · 1.27 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
using System;
using System.Collections.Generic;
using System.IO;
namespace BeaconScan
{
public static class LocalFileHelper
{
// Method to retrieve a list of files in the specified directory
public static List<FileItem> GetLocalFileList(string localPath)
{
var fileList = new List<FileItem>();
try
{
if (Directory.Exists(localPath))
{
var entries = Directory.EnumerateFileSystemEntries(localPath);
foreach (var entry in entries)
{
fileList.Add(new FileItem
{
Name = Path.GetFileName(entry), // Extract the file or directory name
Type = Directory.Exists(entry) ? "D" : "F" // Determine type (Directory/File)
});
}
}
else
{
throw new DirectoryNotFoundException($"Directory {localPath} does not exist.");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error retrieving file list: {ex.Message}");
}
return fileList;
}
}
}