我正在使用Zip存档方法来压缩文件夹中的文件。但是,需要在特定时间从一个文件夹中读取最多10个文件并将其压缩。如果有大量文件(例如100),则需要使用C#创建10个zip文件夹。
我该如何实现? 我已经在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");
}
答案 0 :(得分:1)
伪代码:
在循环中(i = 0; 10 * i
要快乐:)