简体   繁体   English

如何使用密码保护文件夹中的多个压缩文件?

[英]How to zip with password protected the multiple zipped file from a folder?

i'm working on the program to zip the zipped files in a folder with a password protected.我正在开发将压缩文件压缩到受密码保护的文件夹中的程序。 For example i have multiple zipped file in a folder D:\\Work\\ZippedFile which is ABC.zip, CDE.zip, TZE.zip.例如,我在文件夹 D:\\Work\\ZippedFile 中有多个压缩文件,即 ABC.zip、CDE.zip、TZE.zip。 I want to zip all the zipped file into one zip file named AllFile.zip with a password protected.我想将所有压缩文件压缩到一个名为 AllFile.zip 且受密码保护的 zip 文件中。 What have i tried so far is as below:到目前为止我尝试过的内容如下:

string[] dirs = Directory.GetDirectories(@"D:\Work\ZippedFile");
foreach (string dir in dirs)
if (file.Contains(".zip"))
{
    using (var zip = new ZipFile())
    {
        string filename = file.Substring(51);
        zip.Password = "Abc!23";
        zip.Encryption = EncryptionAlgorithm.WinZipAes256;
        zip.AddFile(file, "");
        zip.Save(dir + "\\" + "AllFile.zip");
    }
}                    

I know this will output a single zip file for each zipped file, I hope somebody can give me an idea on how to achieve the right output.我知道这将为每个压缩文件输出一个 zip 文件,我希望有人能给我一个关于如何实现正确输出的想法。 Thanks in advance.提前致谢。

Don't create a new zip file for each existing zip file.不要为每个现有的 zip 文件创建一个新的 zip 文件。 Create a single new zip file and add all the existing zip files to it.创建一个新的 zip 文件并将所有现有的 zip 文件添加到其中。

using (var zip = new ZipFile())
{
    string[] dirs = Directory.GetDirectories(@"D:\Work\ZippedFile");

    foreach (string dir in dirs)
    {
        if (file.Contains(".zip"))
        {   
            string filename = file.Substring(51);
            zip.AddFile(file, "");
        }
    }

    zip.Password = "Abc!23";
    zip.Encryption = EncryptionAlgorithm.WinZipAes256;
    zip.Save(dir + "\\" + "AllFile.zip");
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM