Archivator

mail@pastecode.io avatar
unknown
csharp
2 months ago
534 B
2
Indexable
Never
using System.IO.Compression;


Random random = new Random();
Console.WriteLine("Enter file path");
string filePath = Console.ReadLine();


string zipRootPath = "C:\\dotnet\\";

if (File.Exists(filePath))
{
    using (ZipArchive zipArchive = ZipFile.Open(zipRootPath + $"{random.Next(1000):d4}.zip", ZipArchiveMode.Create))
    {
        zipArchive.CreateEntryFromFile(filePath, Path.GetFileName(filePath));
    }
    Console.WriteLine("successfully archived");
}
else
{
    Console.WriteLine("Can't find file");
}
Leave a Comment