简体   繁体   中英

C# - How to check if zip file is split?

I want to support split zip files in my project, and to have different implementations case the zip file is split or not. How do I check if the zip file is split?

    using Ionic.Zip;
    protected static bool IsZipFileSplit(string filePath)
    {
        try
        {
            ZipFile zipFile = new ZipFile(filePath);
            bool isSplit = ?????
            return isSplit;
        }
        catch (ZipException) { }
        catch (IOException) { }
     }

At the moment i'm using Ionic.Zip (DotNetZip Library) . As I understand, it does not export any public data regarding if a zip file is split or not. It does have the public property NumberOfSegmentsForMostRecentSave, but the value refers only to the last save of the current zip file and not for new zip files opened with existing split zip file path.

Ionic.Zip library did not support at that time working with split zip files. After our research we chose to work with DotNetZip library which supports working with split zip files.

  • To check if the zipFile is split, you can look at the zipFile.Info string, which will mention the number of segments ("disks") it contains. if the number is 0, the file is not split.

Taken from the DotNetZip.ZipFile.Info property:

 public string Info
{
  get
  {
    StringBuilder stringBuilder = new StringBuilder();
    ...
    stringBuilder.Append(string.Format("     disk with CD: {0}\n", (object)this._diskNumberWithCd));
    return stringBuilder;
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM