C#ZipFile:仅压缩文件夹的内容

knz*_*nzo 0 .net c# zipfile

我正在使用ZipFile.CreateFromDirectory方法在C#中压缩目录:

private void createZIP()
{
    string startPath = @"c:\example\start";
    string zipPath = @"c:\example\result.zip";
    ZipFile.CreateFromDirectory(startPath, zipPath,  CompressionLevel.Fastest, true); 
}
Run Code Online (Sandbox Code Playgroud)

它一般都在工作,但我只想要zip文件中/ start /文件夹的内容,而不是目录本身.

现在:

result.zip
--start
---- file1.txt
---- file2.txt
Run Code Online (Sandbox Code Playgroud)

我多么想要:

result.zip
-- file1.txt
-- file2.txt
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

小智 6

ZIPFile.CreateFromDirectory传递值为true 的最后一个参数确定目录本身是否应作为ZIP的根目录包含在内.如果将其更改为false,则应该按照您的意愿工作.

ZipFile.CreateFromDirectory(startPath, zipPath,  CompressionLevel.Fastest, false); 
Run Code Online (Sandbox Code Playgroud)