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. tomcat下的https项目创建与部署

    1.1 生成keystore文件及导出证书 步奏1:打开控制台,运行: %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (如果你已经 ...

  2. MSSQL导入导出数据

    /******* 导出到excel */ EXEC master..xp_cmdshell 'bcp SettleDB.dbo.shanghu out c:\temp1.xls -c -q -S&qu ...

  3. QueryRunner类

    该类简单化了SQL查询,它与ResultSetHandler组合在一起使用可以完成大部分的数据库操作,能够大大减少编码量. QueryRunner类提供了两个构造方法: 默认的构造方法 需要一个 ja ...

  4. vc6 编译问题

    Compiling...main.cppLinking...MSVCRT.lib(MSVCRT.dll) : error LNK2005: _malloc already defined in LIB ...

  5. frame中隐藏横向滚动条

    设置frame的scrolling="yes",在右侧页面的body里加入: style="overflow-x:hidden;"  如:<body st ...

  6. C语言面试题汇总之一

    C语言面试题汇总之一 1.static有什么用途?(请至少说明两种) l 限制变量的作用域: 设置变量的存储域. 2.引用和指针有什么区别? 引用必须被初始化,指针不必: 引用初始化以后不能被改变,指 ...

  7. 在django中使用自定义标签实现分页功能

    效果演示: github地址:https://github.com/mncu/django_projects/tree/master/django_projects/pagination_test 本 ...

  8. 初尝 JFinal 项目(一)

    temp1: JFinal项目与JAVA项目类似,有属性方法.操作方法.Sql语句操作.jdbc.配置文件 对比:|| JAVA: Bean / Srv(Server) / SqlMap / jdbc ...

  9. bat脚本命令循环运行程序 ,然后指定时间退出。

    @echo offtitle EcCheck // 显示标题:loopif "%time%" GTR "23:00.00" (exit) else goto t ...

  10. log4net注意事项

    log4net的配置信息可以直接配置在系统的配置文件中,也可以单独写一个配置文件,文件名随便起,如log4net.config,单独的文件属性“复制到输出目录”应该是true.因为log4net框架会 ...