DotNetZip add files without creating folders

2019-01-11 12:13发布

using (ZipFile zip = new ZipFile())
{
    foreach(string file in Directory.GetFiles(folder))
    {
        zip.AddFile(file, Path.GetFileName(file));
    }
    zip.Save("test.zip"));
}

Each time I add a file, it's creating a new subfolder for it.

So I want to end up with:

test.zip
    -  myDoc.doc
    -  myPdf.pdf

but I'm ending up with:

test.zip
    -  myDoc.doc
        -  myDoc.doc
    -  myPdf.pdf
        -  myPdf.pdf

3条回答
再贱就再见
2楼-- · 2019-01-11 12:55

How about just:

zip.AddFile(file,"");

or

zip.AddFile(file,@"\");
查看更多
孤傲高冷的网名
3楼-- · 2019-01-11 13:02

This is what I did and it worked.

zip.AddFile(file, "..\...\".ToString.Replace("..\...\", Nothing))

It sends the file back to 2 folders and replaces the .....\ with Nothing.

查看更多
再贱就再见
4楼-- · 2019-01-11 13:02
zip.AddFile(file, "..\...\".ToString.Replace("..\...\", null))
查看更多
登录 后发表回答