小编php*_*rtf的帖子

C# 解压缩目录中的所有嵌套 zip,同时保留文件结构

我正在尝试解压缩目录中的所有 zip,其中有时包含多层嵌套的 zip。我还想在提取的版本中保留原始的 zip 嵌套结构。我可以使用一层 zip 执行我想要的操作,但不能使用嵌套 zip 或子文件夹内的 zip。

例如,我想将起始文件夹中的所有内容如下所示:

[Starting Folder]
-Zip1.zip
--NestedZip1.zip
---text1.txt
--NestedZip2.zip
---text2.txt
-Zip2.zip
--[Subfolder1]
---Zip3.zip
----text3.txt
---Zip4.zip
----text4.txt
Run Code Online (Sandbox Code Playgroud)

并将所有内容提取到同一起始目录中的文件夹中:

[Starting Folder]
[Extracted Folder]
-Zip1 (folder)
--NestedZip1 (folder)
---text1.txt
--NestedZip2 (folder)
---text2.txt
-Zip2 (folder)
--[Subfolder1]
---Zip3 (folder)
----text3.txt
---Zip4 (folder)
----text4.txt
Run Code Online (Sandbox Code Playgroud)

现在我正在使用它来解压缩 MyGlobals.finalPathForWork (这是起始目录)中的所有文件,它可以工作,但只能解压缩一层 zip。我需要它以某种方式再次运行,以防第一层拉链中有拉链。

        public static void MyMethod3()
    {
        string startPath = MyGlobals.finalPathForWork;
        string extractPath = MyGlobals.finalPathForWork + @"\\Extracted\";
        Directory.GetFiles(startPath, "*.zip", SearchOption.AllDirectories).ToList()
            .ForEach(zipFilePath =>
            {
                var extractPathForCurrentZip = Path.Combine(extractPath, Path.GetFileNameWithoutExtension(zipFilePath));
                if (!Directory.Exists(extractPathForCurrentZip))
                {
                    Directory.CreateDirectory(extractPathForCurrentZip); …
Run Code Online (Sandbox Code Playgroud)

c# unzip

1
推荐指数
1
解决办法
1958
查看次数

C# 在 for 循环期间检查取消令牌

我不完全理解取消令牌,但我相信这是我需要使用的。

我有一个充满文件路径的列表框,以及一个方法 ( ProcesstListSort),它遍历列表框中的每个文件路径并根据文件类型执行不同的方法。ProcessListSort从另一个方法调用,即从按钮单击调用。我试图BeginEverything在后台任务中运行,因为它锁定了 UI。在这种情况下实现取消令牌检查的最佳位置是什么?

单击此按钮开始该过程:

public async void button1_Click(object sender, EventArgs e)
{
    Task task1 = new Task(BeginEverything);
    task1.Start();
    await task1;
}
Run Code Online (Sandbox Code Playgroud)

哪个启动这个:

public void BeginEverything()
{
    CreateThing1();
    CreateThing2();
    ProcessListSort();  //This is the one I think I need to interrupt because it's the longest
    CreateThing3();
    CreateThing4();
}
Run Code Online (Sandbox Code Playgroud)

在这里启动最长的任务(根据文件类型对文件进行排序和执行其他方法,将文件路径传递给其他方法):

public void ProcessListSort()
{
    for (int i = 0; i < listBox2.Items.Count; i++)
    {
        string p = listBox2.Items[i].ToString();
        FileAttributes attr = File.GetAttributes(p);

        if (p.EndsWith(".zip"))
        {
            Method1(p); …
Run Code Online (Sandbox Code Playgroud)

c# for-loop winforms cancellation cancellation-token

1
推荐指数
1
解决办法
235
查看次数