正在压缩文件preserving的目录结构 [英] Zipping files preserving the directory structure

查看:210
本文介绍了正在压缩文件preserving的目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是DotNetZip DLL(HTTP://dotnetzip.$c$cplex.com/)从codePLEX来压缩在我的程序的某些文件

I am using the DotNetZip DLL(http://dotnetzip.codeplex.com/) from codeplex to zip some files in my program.

问题,我面对的是压缩和解是preserving的目录结构,当我抽出所有的父文件夹越来越再次创建,那么只有我可以查看文件的zip文件中的文件后。这是非常恼人的当源文件存在于

Problem I am facing is after zipping the files it is preserving the directory structure and when I am extracting the zip file all the parent folders are getting created again and then only I am able to view the file. It is very annoying when the source file exists in

所以,如果我给G荏苒文件:\存档\ LogFiles文件\ W3SVC1 \ abc.log和提取后创建abc.zip文件,文件夹归档\ LogFiles文件\ W3SVC1 \越来越创建,然后只有我我能看到abc.log文件。在这里,G:是我的共享驱动器的名称。

So, if I am zipping a file from g:\Archive\LogFiles\W3SVC1\abc.log and creating 'abc.zip' file after extracting it, folders Archive\LogFiles\W3SVC1\ are getting created and then only I am able to see abc.log file. Here 'g:' is the name of my shared drive.

我想摆脱所有这些父文件夹,这样我就可以马上提取物,并达到压缩文件并打开它。我已经检查了压缩文件的路径属性,它是显示归档\ LogFiles文件\ W3SVC1。不知怎的,我需要删除这个编程,但不容易找到任何选项。

I want to get rid of all these parent folders so that I can straight away extract and reach to the zipped file and open it. I have checked the Path property of the Zipped file and it is showing Archive\LogFiles\W3SVC1. Somehow I need to remove this programatically but not finding any option easily.

code我现在用的就是这样的:

Code I am using is like this:

using (ZipFile zip = new ZipFile())
{
    if (fileExtension != null)
    {
        zip.AddFiles(from f in sourceDir.GetFiles() where f.FullName.EndsWith(fileExtension) select f.FullName);
    }
    else
    {
        zip.AddFiles(from f in sourceDir.GetFiles() select f.FullName);
    }
    zip.Save(DestinationDir + OutFileName);
}

我也尝试过Addfiles的重载方法的reserveDirectoryHierarchy设置为假,但没有任何好处。

I have also tried the overload method of Addfiles by setting the reserveDirectoryHierarchy to 'false' but no benefit.

请让我知道该怎么做。

提前非常感谢。

推荐答案

我是不是叫Addfiles的重载方法正确。而不是空的我通过空字符串,现在还不是preserving的目录结构。 所以更新code是象下面这样:

I was not calling the overload method of Addfiles properly. instead of Null I passed empty string and now it is not preserving the directory structure. so the updated code is like below:

if (fileExtension != null)
                {
                    zip.AddFiles(from f in sourceDir.GetFiles() where f.FullName.EndsWith(fileExtension) select f.FullName,false,"");

                }
                else
                {
                    zip.AddFiles(from f in sourceDir.GetFiles() select f.FullName,false,"");
                }
                zip.Save(DestinationDir + OutFileName);

这篇关于正在压缩文件preserving的目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆