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 プロパティの部分が含まれており、サブディレクトリ階層は含まれません。 たとえば、CreateEntryFromFile メソッドを使用して zip アーカイブに 2 つのエントリを作成し、最初のエントリの名前としてNewEntry.txtを指定し、2 番目のエントリのAddedFolder\\NewEntry.txtを指定すると、両方のエントリが NewEntry.txt プロパティにNameされます。 最初のエントリはNewEntry.txt プロパティにもFullNameされますが、2 番目のエントリは AddedFolder\\NewEntry.txt プロパティにFullNameされます。
Windowsでは、NTFS ルールによりコロン (:) も区切り文字として扱われます。これにより、Nameがプラットフォーム間で異なる可能性があります。 プラットフォームに依存しない動作では、 FullNameを使用できます。これは、アーカイブに格納されている完全なエントリ名を常に反映します。
例
次の例は、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