List的使用
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;
}
}
随机推荐
- 115、定时器(TimerTask+Timer+Handler)
public class TimerUtils { public static Activity act; public static List<MaiDianModels> listMa ...
- ISurfaceOp 接口生成等高线
(1)ISurfaceOp.Contour 根据DEM生成等高线图层: private void button1_Click(object sender, EventArgs e) { ...
- RabbitMQ、Memcache、Redis(队列、缓存)
RabbitMQ 一.解释 RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统.他遵循Mozilla Public License开源协议. MQ全称为Message Queue, 消 ...
- php创建多级目录的两种方法
1.使用递归的思想 function mkdirs_2($path){ if(!is_dir($path)){ mkdirs_2(dirname($path)); if(!mkdir($path, 0 ...
- postman+newman(2)
用newman执行带环境变量的postman测试用例 1.在postman中将用例项目文件导出外还需将环境变量文件导出,如下: 2.newman执行如下: newman -c 测试用例文件 -e 环境 ...
- [转载]:Fortran字符串的故事
一. Fortran 字符串与 C 字符串的区别 Fortran的字符串处理能力其实很弱,关于字符串的语法还很落后.它与 C 字符串最大的区别就是:Fortran字符串是固定长度的,没有 \0 结束 ...
- phpexcel简单用法
<?php /*php生成excel完整实例代码现求:php生成excel完整实例代码最好能说明如何调用!谢谢java_sunhui4 | 浏览 8131 次 2014-09-24 14:502 ...
- NO.2
虚拟语气的终结版.英语语法的终结时刻.迎接新的英语挑战!!!
- avalon2学习教程14动画使用
avalon2实际上没有实现完整的动画模块,它只是对现有的CSS3动画或jquery animate再包装一层. 我们先说如何用CSS3为avalon实现动画效果.首先要使用avalon.effect ...
- EAS linux挂载数据盘
查看数据盘名称 fdisk -l 假设没有挂载的数据盘为/dev/xvdb 格式化数据盘 mkfs.ext3 /dev/xvdb 添加自动挂载 mkdir /data echo '/dev/xvdb ...