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;
                            }
                        }
    

      

  • 相关阅读:
    搜狗搜索用户体验
    第六周学习进度条
    对我们团队NBPL的改进方案意见
    钱多多软件制作第七天
    团队冲刺第二周05
    团队冲刺第二周04
    团队冲刺第二周03
    输入法评价
    团队冲刺第二周02
    团队冲刺第二周01
  • 原文地址:https://www.cnblogs.com/panjinzhao/p/3516573.html
Copyright © 2011-2022 走看看