ZipArchiveEntry.Name 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 Zip 封存中的項目檔名。
public:
property System::String ^ Name { System::String ^ get(); };
public string Name { get; }
member this.Name : string
Public ReadOnly Property Name As String
屬性值
Zip 封存中的項目檔名。
備註
屬性 Name 包含屬性的 FullName 部分,該部分會遵循最終目錄分隔符 (\) ,而且不包含子目錄階層。 例如,如果您使用 方法在 zip CreateEntryFromFile 封存中建立兩個專案,並提供 NewEntry.txt 作為第一個專案的名稱和第AddedFolder\\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