Moved to ADO2024 PI#
Ran SortCodeMethods
This commit is contained in:
40
ADO2024/PI3/Helper-2024-08-20.cs
Normal file
40
ADO2024/PI3/Helper-2024-08-20.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
namespace File_Folder_Helper.ADO2024.PI3;
|
||||
|
||||
internal static partial class Helper20240820
|
||||
{
|
||||
|
||||
internal static void MoveFilesWithSleep(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
string checkFile;
|
||||
string checkDirectory;
|
||||
int sleep = int.Parse(args[4]);
|
||||
string searchPattern = args[3];
|
||||
string sourceDirectory = args[0];
|
||||
string destinationDirectory = args[2];
|
||||
string source = Path.GetFullPath(sourceDirectory);
|
||||
FileInfo[] collection = Directory.GetFiles(source, "*", SearchOption.TopDirectoryOnly).Select(l => new FileInfo(l)).ToArray();
|
||||
string[] files = (from l in collection orderby l.LastWriteTime select l.FullName).ToArray();
|
||||
logger.LogInformation("With search pattern '{SearchPattern}' found {files}", searchPattern, files.Length);
|
||||
foreach (string file in files)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
checkFile = file.Replace(source, destinationDirectory);
|
||||
if (checkFile == file)
|
||||
throw new NotSupportedException("Replace failed!");
|
||||
checkDirectory = Path.GetDirectoryName(checkFile) ?? throw new NotSupportedException();
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(file, checkFile);
|
||||
Thread.Sleep(sleep);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{ logger.LogInformation(ex, "Inner loop error!"); }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user