mirror of
https://github.com/whoeevee/ivinject.git
synced 2026-01-08 23:25:03 +00:00
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
namespace ivinject.Common;
|
|
|
|
internal static class DirectoryExtensions
|
|
{
|
|
internal static string TempDirectoryPath()
|
|
{
|
|
return Path.Combine(
|
|
Path.GetTempPath(),
|
|
Path.ChangeExtension(Path.GetRandomFileName(), null)
|
|
);
|
|
}
|
|
|
|
internal static string HomeDirectoryPath() =>
|
|
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
|
|
|
internal static void CopyDirectory(string sourceDir, string destinationDir, bool recursive)
|
|
{
|
|
var dir = new DirectoryInfo(sourceDir);
|
|
|
|
if (!dir.Exists)
|
|
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
|
|
|
|
var dirs = dir.GetDirectories();
|
|
|
|
Directory.CreateDirectory(destinationDir);
|
|
|
|
foreach (var file in dir.GetFiles())
|
|
{
|
|
var targetFilePath = Path.Combine(destinationDir, file.Name);
|
|
file.CopyTo(targetFilePath);
|
|
}
|
|
|
|
if (!recursive) return;
|
|
|
|
foreach (var subDir in dirs)
|
|
{
|
|
var newDestinationDir = Path.Combine(destinationDir, subDir.Name);
|
|
CopyDirectory(subDir.FullName, newDestinationDir, true);
|
|
}
|
|
}
|
|
} |