I found the code below on stack overflow which I tried but didn't know how to use it fully.
Basically I want to be able to zip all the files separately using foreach loop but I won't have a list of the files as they change each time.
So how can I get a list of the folders/directories inside the root directory into an array?
public static void CreateZipFile(string fileName, IEnumerable<string> files)
{
var zip = ZipFile.Open(fileName, ZipArchiveMode.Create);
foreach (var file in files)
{
zip.CreateEntryFromFile(file, Path.GetFileName(file), CompressionLevel.Optimal);
}
zip.Dispose();
}
Normally I just use DotNetZip
And this code:
Where
zipName
is the name of zip archive you want to create andfileNames
are names of files you want to put in it.