zoukankan      html  css  js  c++  java
  • List的使用

     List<string> AllFilesPath = new List<string>();
                    if (filesOrDirectoriesPaths.Length > 0) // get all files path
                    {
                        for (int i = 0; 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;
                            }
                        }
    

      

  • 相关阅读:
    MSP430:管脚的第二功能选择
    MSP430 WDT
    MSP430 G2553 Timer 中断总结
    Timer A UP mode 中断
    AD10 库下载地址
    mysql的视图,事务,索引,外键
    mariadb主从配置
    DNS服务搭建
    数据库的连接查询
    数据库设计及ER模型
  • 原文地址:https://www.cnblogs.com/panjinzhao/p/3516573.html
Copyright © 2011-2022 走看看