This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2023_Stanislav_Mykhailenko/Lesson_7/Task_1/Classes/Operations.cs
Stanislav Mykhailenko f5cf47f213
Add Lesson 7 Task 1
2023-04-19 17:32:11 +03:00

56 lines
No EOL
1.6 KiB
C#

namespace Lesson5.Classes;
using Lesson5.Interfaces;
public class Operations : IOperations
{
public static void GetFileInfo(string path)
{
var info = new FileInfo(path);
Console.WriteLine($"Name: {info.Name}");
Console.WriteLine($"Creation time: {info.CreationTime}");
Console.WriteLine($"Length: {info.Length}");
}
public static async Task CopyAsync(string source, string destination, bool keepSource=true)
{
try
{
destination = Validation.Check(source, destination);
}
catch (PathConflictException)
{
Console.WriteLine("Conflict.");
return;
}
bool exists = await Task.Run(() => Directory.Exists(source) || File.Exists(source));
if (exists)
if (keepSource)
{
if (Directory.Exists(source))
await Task.Run(() => CopyDirectory.Copy(source, destination, true));
else if (File.Exists(source))
await Task.Run(() => File.Copy(source, destination));
}
else
{
await Task.Run(() => Directory.Move(source, destination));
}
else
Console.WriteLine("Not found.");
}
public static async Task DeleteAsync(string path)
{
if (Directory.Exists(path))
await Task.Run(() => Directory.Delete(path, true));
else if (File.Exists(path))
await Task.Run(() => File.Delete(path));
else
Console.WriteLine("Not found.");
}
}