68 lines
1.7 KiB
C#
68 lines
1.7 KiB
C#
|
using System;
|
|||
|
using System.IO;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
namespace BlueWest.Tools
|
|||
|
{
|
|||
|
public static class PathUtils
|
|||
|
{
|
|||
|
public static void CreateDirectory(string directory)
|
|||
|
{
|
|||
|
Directory.CreateDirectory(directory);
|
|||
|
}
|
|||
|
|
|||
|
private static string ListDirectories(string path)
|
|||
|
{
|
|||
|
var dirInfo = new DirectoryInfo(path);
|
|||
|
var sb = new StringBuilder();
|
|||
|
|
|||
|
|
|||
|
var dirs = dirInfo.EnumerateDirectories("*", new EnumerationOptions
|
|||
|
{ RecurseSubdirectories = false });
|
|||
|
|
|||
|
foreach (var name in dirs)
|
|||
|
{
|
|||
|
if (name.Name != "") sb.Append(name.Name + "\n");
|
|||
|
}
|
|||
|
|
|||
|
return sb.ToString();
|
|||
|
}
|
|||
|
|
|||
|
public static string ListFiles(string path)
|
|||
|
{
|
|||
|
DirectoryInfo d = new(path);
|
|||
|
|
|||
|
FileInfo[] files = d.GetFiles();
|
|||
|
|
|||
|
var sb = new StringBuilder();
|
|||
|
|
|||
|
for (int i = 0; i < files.Length; i++)
|
|||
|
{
|
|||
|
var file = files[i];
|
|||
|
sb.Append(file.Name) ;
|
|||
|
if (i == files.Length - 1) continue;
|
|||
|
sb.Append("\n") ;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
return sb.ToString();
|
|||
|
}
|
|||
|
|
|||
|
public static string ListAssemblyPathFiles()
|
|||
|
{
|
|||
|
var assemblyLcation = AssemblyUtils.GetAssemblyPath();
|
|||
|
return ListAll(assemblyLcation);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
internal static string ListAll(string path)
|
|||
|
{
|
|||
|
var result = "";
|
|||
|
result += "-- Files:\n";
|
|||
|
result += ListFiles(path);
|
|||
|
result += "\n-- Folders:\n";
|
|||
|
result += ListDirectories(path);
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|