38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using System.Diagnostics;
|
|
|
|
namespace File_Folder_Helper.Day;
|
|
|
|
internal static partial class Helper20240724
|
|
{
|
|
|
|
internal static void CopyDirectories(ILogger<Worker> logger, List<string> args)
|
|
{
|
|
string[] files;
|
|
Process process;
|
|
string checkDirectory;
|
|
string filter = args[3];
|
|
string replaceWith = args[4];
|
|
string searchPattern = args[2];
|
|
string sourceDirectory = Path.GetFullPath(args[0]);
|
|
string[] foundDirectories = Directory.GetDirectories(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
|
logger.LogInformation($"Found {foundDirectories.Length} directories");
|
|
foreach (string foundDirectory in foundDirectories)
|
|
{
|
|
if (!foundDirectory.Contains(filter))
|
|
continue;
|
|
logger.LogDebug(foundDirectory);
|
|
checkDirectory = foundDirectory.Replace(filter, replaceWith);
|
|
if (Directory.Exists(checkDirectory))
|
|
{
|
|
files = Directory.GetFiles(checkDirectory, "*", SearchOption.AllDirectories);
|
|
if (files.Length > 0)
|
|
continue;
|
|
Directory.Delete(checkDirectory);
|
|
}
|
|
process = Process.Start("cmd.exe", $"/c xCopy \"{foundDirectory}\" \"{checkDirectory}\" /S /E /I /H /Y");
|
|
process.WaitForExit();
|
|
}
|
|
}
|
|
|
|
} |