ZipArchiveEntry.Name 属性

定义

获取在 zip 存档中的项的文件名。

public:
 property System::String ^ Name { System::String ^ get(); };
public string Name { get; }
member this.Name : string
Public ReadOnly Property Name As String

属性值

String

在 zip 存档中的项的文件名。

注解

Name属性包含与最终目录分隔符 () \ 之后的属性部分FullName,不包括子目录层次结构。 例如,如果使用该方法在 zip 存档CreateEntryFromFile中创建两个条目,并为第一个条目和第AddedFolder\\NewEntry.txt二个条目提供NewEntry.txt名称,则这两个条目都将在属性中Name具有NewEntry.txt。 第一个条目也将在属性中FullName具有NewEntry.txt,但第二个条目将在属性中FullName具有AddedFolder\\NewEntry.txt

示例

以下示例演示如何从 zip 存档检索条目并评估条目的属性。 它使用 Name 属性来显示条目的名称,以及 Length 用于计算压缩文件量的属性 CompressedLength

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string zipPath = @"c:\example\result.zip";

            using (ZipArchive archive = ZipFile.OpenRead(zipPath))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    float compressedRatio = (float)entry.CompressedLength / entry.Length;
                    float reductionPercentage = 100 - (compressedRatio * 100);

                    Console.WriteLine (string.Format("File: {0}, Compressed {1:F2}%", entry.Name, reductionPercentage));
                }
            }
        }
    }
}
Imports System.IO
Imports System.IO.Compression

Module Module1

    Sub Main()
        Dim zipPath As String = "c:\example\result.zip"

        Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
            For Each entry As ZipArchiveEntry In archive.Entries
                Dim compressedRatio As Single = entry.CompressedLength / entry.Length
                Dim reductionPercentage As Single = 100 - (compressedRatio * 100)

                Console.WriteLine(String.Format("File: {0}, Compressed {1:F2}%", entry.Name, reductionPercentage))
            Next
        End Using
    End Sub

End Module

适用于