/// 
        /// 解压功能(解压压缩文件到指定目录)
        /// 
        /// 待解压的文件
        /// 指定解压目标目录
        public void UnZip(string FileToUpZip, string ZipedFolder, string Password)
        {
            if (!File.Exists(FileToUpZip))
            {
                return;
            }            if (!Directory.Exists(ZipedFolder))
            {
                Directory.CreateDirectory(ZipedFolder);
            }            ZipInputStream s = null;
            ZipEntry theEntry = null;            string fileName;
            FileStream streamWriter = null;
            try
            {
                s = new ZipInputStream(File.OpenRead(FileToUpZip));
                s.Password = Password;
                while ((theEntry = s.GetNextEntry()) != null)
                {
                    if (theEntry.Name != String.Empty)
                    {
                        fileName = Path.Combine(ZipedFolder, theEntry.Name);
                        /**/
                        ///判断文件路径是否是文件夹
                        if (fileName.EndsWith("/") || fileName.EndsWith("\\"))
                        {
                            Directory.CreateDirectory(fileName);
                            continue;
                        }                        streamWriter = File.Create(fileName);
                        int size = 2048;
                        byte[] data = new byte[2048];
                        while (true)
                        {
                            size = s.Read(data, 0, data.Length);
                            if (size > 0)
                            {
                                streamWriter.Write(data, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (ZipException err)
            {
                MessageBox.Show(err.Message);
            }
            finally
            {
                if (streamWriter != null)
                {
                    streamWriter.Close();
                    streamWriter = null;
                }
                if (theEntry != null)
                {
                    theEntry = null;
                }
                if (s != null)
                {
                    s.Close();
                    s = null;
                }
                GC.Collect();
                GC.Collect(1);
            }
        }
这是我在网上找的将压缩包所有文件解压缩的方法,调用方法如下:
zip.UnZip(@"F:\zip.zip", @"F:\test\", "");
现在想把这个方法修改一下,能够让我用循环的方式实现逐个解压缩出包中的文件,如何修改代码?

解决方案 »

  1.   

    你还是 需要 调用这个方法 里面的部分信息 预读 解压包里面的内容, 然后 根据 预读的内容, 指定解压文件
    就在这里判断
     while ((theEntry = s.GetNextEntry()) != null)
                    {
                        if (theEntry.Name != String.Empty)
      

  2.   

    http://www.cnblogs.com/chg2001868/archive/2009/02/05/1384670.html
      

  3.   

    我好象明白了,应该将theEntry的值放在调用处,进行循环,然后将该theEntry值 传入,试下