예제 #1
0
        /// <summary>
        /// 获得压缩包内原文件总大小
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="fileFilter"></param>
        /// <param name="directoryFilter"></param>
        /// <returns></returns>
        public static long GetZipFileSize(string fileName, string fileFilter, string directoryFilter)
        {
            long b = 0;

            using (ZipFile zipFile = new ZipFile(fileName))
            {
                PathFilter localFileFilter = new PathFilter(fileFilter);
                PathFilter localDirFilter  = new PathFilter(directoryFilter);

                if (zipFile.Count == 0)
                {
                    return(0);
                }
                for (int i = 0; i < zipFile.Count; ++i)
                {
                    ZipEntry e = zipFile[i];
                    if (e.IsFile)
                    {
                        string path = Path.GetDirectoryName(e.Name);
                        if (localDirFilter.IsMatch(path))
                        {
                            if (localFileFilter.IsMatch(Path.GetFileName(e.Name)))
                            {
                                b += e.Size;
                            }
                        }
                    }
                }
            }
            return(b);
        }
예제 #2
0
        public static void ListZipFile(string fileName, string fileFilter, string directoryFilter)
        {
            using (ZipFile zipFile = new ZipFile(fileName))
            {
                PathFilter localFileFilter = new PathFilter(fileFilter);
                PathFilter localDirFilter  = new PathFilter(directoryFilter);

                if (zipFile.Count == 0)
                {
                    Console.WriteLine("No entries to list");
                }
                else
                {
                    for (int i = 0; i < zipFile.Count; ++i)
                    {
                        ZipEntry e = zipFile[i];
                        if (e.IsFile)
                        {
                            string path = Path.GetDirectoryName(e.Name);
                            if (localDirFilter.IsMatch(path))
                            {
                                if (localFileFilter.IsMatch(Path.GetFileName(e.Name)))
                                {
                                    Console.WriteLine(e.Name);
                                }
                            }
                        }
                        else if (e.IsDirectory)
                        {
                            if (localDirFilter.IsMatch(e.Name))
                            {
                                Console.WriteLine(e.Name);
                            }
                        }
                        else
                        {
                            Console.WriteLine(e.Name);
                        }
                    }
                }
            }
        }