C#仅提取最新的压缩文件

时间:2018-05-17 12:00:25

标签: c#

最后让我的代码正常工作,但我需要在目录中提取最新的压缩文件。

真的不知道如何解决这个问题,有人可以指出我正确的方向,想到使用修改日期和时间,请看下面的代码......

using System;
using System.IO;
using System.IO.Compression;


namespace unZipMe
{
    class Program
    {


        static void Main(string[] args)
        {



            DirectoryInfo file = new DirectoryInfo(@"c:\Temp\ZipSampleExtract");


            if(file.Exists)
            {
                file.Delete(true);
            }

            string myDir = (@"c:\Temp\ZipSampleExtract");


            bool exists = System.IO.Directory.Exists(myDir);

            if (!exists)
            {
                System.IO.Directory.CreateDirectory(myDir);
            }



            //provide the folder to be zipped
            //string folderToZip = @"c:\Temp\ZipSample";

            //provide the path and name for the zip file to create
            string zipFile = @"c:\Temp\ZipSampleOutput\MyZippedDocuments.zip";

            //call the ZipFile.CreateFromDirectory() method
            //ZipFile.CreateFromDirectory(folderToZip, zipFile, CompressionLevel.Optimal, false);

            //specif the directory to which to extract the zip file


            string extractFolder = @"c:\Temp\ZipSampleExtract\";

            //call the ZipFile.ExtractToDirectory() method
            ZipFile.ExtractToDirectory(zipFile, extractFolder);
        }
    }
}

0 个答案:

没有答案