ZipArchiveEntry.Name 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會取得壓縮壓縮檔中條目的檔案名稱。
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 ,且不包含子目錄階層。 例如,如果你在壓縮壓縮檔中用 CreateEntryFromFile 和 提供了NewEntry.txt第一個條目名稱,AddedFolder\\NewEntry.txt第二個條目分別建立兩個條目,兩個條目都會在該NewEntry.txt屬性中。Name 第一個項目也會在該物業中,NewEntry.txtFullName但第二個項目則是AddedFolder\\NewEntry.txt該FullName物業。
在 Windows 上,冒號(:)也被視為分隔符,因為 NTFS 規則可能導致不同平台的 Name 不同。 對於平台無關的行為,你可以使用 FullName,它總是反映存檔中完整的條目名稱。
範例
以下範例說明如何從壓縮壓縮包中檢索條目並評估條目的屬性。 它使用 屬性 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