List<string> AllFilesPath = new List<string>();
if (filesOrDirectoriesPaths.Length > ) // get all files path
{
for (int i = ; i < filesOrDirectoriesPaths.Length; i++)
{
if (File.Exists(@strZipTopDirectoryPath + filesOrDirectoriesPaths[i]))
{
AllFilesPath.Add(strZipTopDirectoryPath + filesOrDirectoriesPaths[i]);
}
else if (Directory.Exists(@strZipTopDirectoryPath + filesOrDirectoriesPaths[i]))
{
GetDirectoryFiles(filesOrDirectoriesPaths[i], AllFilesPath);
}
}
}
 for (int i = 0; i < AllFilesPath.Count; i++)
{
string strFile = AllFilesPath[i].ToString();
try
{
if (strFile.Substring(strFile.Length - 1) == "") //folder
{
string strFileName = strFile.Replace(strZipTopDirectoryPath, "");
if (strFileName.StartsWith(""))
{
strFileName = strFileName.Substring(1);
}
ZipEntry entry = new ZipEntry(strFileName);
entry.DateTime = DateTime.Now;
zipOutputStream.PutNextEntry(entry);
}
else //file
{
FileStream fs = File.OpenRead(strFile); byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length); string strFileName = strFile.Replace(strZipTopDirectoryPath, "");
if (strFileName.StartsWith(""))
{
strFileName = strFileName.Substring(0);
}
ZipEntry entry = new ZipEntry(strFileName);
entry.DateTime = DateTime.Now;
zipOutputStream.PutNextEntry(entry);
zipOutputStream.Write(buffer, 0, buffer.Length); fs.Close();
fs.Dispose();
}
}
catch
{
continue;
}
}

  

随机推荐

  1. CentOS6.4 安装 erlang

    wget http://www.erlang.org/download/otp_src_17.0.tar.gz -P /usr/local/src/ wget http://www.erlang.or ...

  2. Flex中设置Camera的视频清晰质量的最佳配合

    今天需要设置Flex中的Camera组件的一些属性,后来发现清晰度不是很高,于是捣鼓了上午半天,设置了很多的参数,竟然发现手册上就是有现成的一些设置方法,郁闷!不过我还是专门设置了几个有用和必要的属性 ...

  3. 关于JQuery的一些知识点

    1.jQuery的入口函数 1.1 语法jQuery(document).read(function(){ }); $(function(){ });// ** window.onlaod = fun ...

  4. Spring day02笔记

    spring day01回顾 编写流程(基于xml) 1.导入jar包:4+1 --> beans/core/context/expression | commons-logging 2.编写目 ...

  5. Linux下的段错误(Segmentation fault)

    Linux开发中常见段错误问题原因分析 1 使用非法的内存地址(指针),包括使用未经初始化及已经释放的指针.不存在的地址.受系统保护的地址,只读的地址等,这一类也是最常见和最好解决的段错误问题,使用G ...

  6. PHP 程序员的技术成长规划

    [导读] 按照了解的很多PHP LNMP程序员的发展轨迹,结合个人经验体会,抽象出很多程序员对未来的迷漫,特别对技术学习的盲目和慌乱,简单梳理了这个每个阶段PHP程序员的技术要求,来帮助很多PHP程序 ...

  7. APP分发渠道的竞争分析

    一. 最近几年,手机APP市场发展非常迅速,随着手机的硬件水平的不断升级,大量资本涌入,越来越多的开发者从桌面平台开发转移到移动平台开发,面对数以万计的手机APP,如何推广自己的APP成了难题,APP ...

  8. jquery remove/add css

    <input type="submit" class="btn btn-primary" id="submit" value=&quo ...

  9. checkbox绿色圆圈样式

    抄自: http://www.cnblogs.com/xyzhanjiang/p/3989836.html?utm_source=tuicool&utm_medium=referral < ...

  10. cannot access the system temp folder

    cannot access the system temp folder. please, make sure your application have full control rights on ...