[英]Zip files in C# in batches
I am using Zip Archive method to zip files in a folder. 我正在使用Zip存档方法来压缩文件夹中的文件。 However, there is a requirement to read max 10 files from a folder at a particular time and zip it. 但是,需要在特定时间从一个文件夹中读取最多10个文件并将其压缩。 If there are a large number of files say 100, then 10 zip folders need to be created using C#. 如果有大量文件(例如100),则需要使用C#创建10个zip文件夹。
How do I achieve this? 我该如何实现? I have tried this in Windows forms - 我已经在Windows表单中尝试过-
private void btnZip_Click(object sender, EventArgs e) {
string FolderPathToZip = txtFolderPath.Text.Trim();
//To create unique file name with date and time with nanoseconds.
string ZipFileName = "D:\\backup\\bak-" + DateTime.Now.ToString("ddMMyyyy-HHmmssfffff") + ".zip";
try {
//To check whether D:\Backup folder exists or not.
//If not exists this will create a BACKUP folder.
if (Directory.Exists("D:\\backup")) {} else {
Directory.CreateDirectory("D:\\backup");
}
//TO create a zip file.
ZipFile.CreateFromDirectory(FolderPathToZip, ZipFileName);
} catch (Exception) {
//If system throw any exception message box will display "SOME ERROR"
MessageBox.Show("Some Error");
}
//Display successfully created message to the user.
MessageBox.Show("Zip Filename : " + ZipFileName + " Created Successfully");
}
Psuedo Code: 伪代码:
In a loop (i=0; 10*i<fileList.Count; i++) do the following 在循环中(i = 0; 10 * i <fileList.Count; i ++)执行以下操作
Be Happy :) 要开心 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.