Ready to test
This commit is contained in:
50
Helpers/HelperRenameToOldMoveDeleteOld.cs
Normal file
50
Helpers/HelperRenameToOldMoveDeleteOld.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using Serilog;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static class HelperRenameToOldMoveDeleteOldMerge
|
||||
{
|
||||
|
||||
internal static void RenameToOldMoveDeleteOld(ILogger log, string argsZero)
|
||||
{
|
||||
string checkDirectory = argsZero[0..^1];
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
log.Information(string.Concat("<", checkDirectory, "> doesn't exist!"));
|
||||
else
|
||||
{
|
||||
string renameFile;
|
||||
string destinationFile;
|
||||
List<string> deleteFiles = new();
|
||||
string[] moveFiles = Directory.GetFiles(argsZero, "*", SearchOption.TopDirectoryOnly);
|
||||
log.Information(string.Concat("<", moveFiles.Length, "> to move"));
|
||||
foreach (string moveFile in moveFiles)
|
||||
{
|
||||
destinationFile = string.Concat(checkDirectory, moveFile[argsZero.Length..]);
|
||||
if (!File.Exists(destinationFile))
|
||||
File.Move(moveFile, destinationFile);
|
||||
else
|
||||
{
|
||||
renameFile = Path.ChangeExtension(destinationFile, string.Concat(Path.GetExtension(destinationFile), ".old"));
|
||||
File.Move(destinationFile, renameFile);
|
||||
File.Move(moveFile, destinationFile);
|
||||
deleteFiles.Add(renameFile);
|
||||
}
|
||||
}
|
||||
log.Information(string.Concat("<", deleteFiles.Count, "> to delete"));
|
||||
foreach (string deleteFile in deleteFiles)
|
||||
{
|
||||
for (short i = 0; i < short.MaxValue; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(deleteFile);
|
||||
break;
|
||||
}
|
||||
catch (Exception) { }
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user