ZipArchiveEntry.Name Propriedade

Definição

Obtém o nome de arquivo da entrada no arquivo zip.Gets the file name of the entry in the zip archive.

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

Valor da propriedade

String

O nome de arquivo da entrada no arquivo zip.The file name of the entry in the zip archive.

Comentários

A Name propriedade contém a parte da FullName propriedade que segue o caractere separador de diretório final ( \ ) e não inclui a hierarquia de subdiretórios.The Name property contains the portion of the FullName property that follows the final directory separator character (\), and does not include the subdirectory hierarchy. Por exemplo, se você criar duas entradas em um arquivo zip usando o CreateEntryFromFile método e fornecer NewEntry.txt como o nome para a primeira entrada e AddedFolder\\NewEntry.txt para a segunda entrada, ambas as entradas terão NewEntry.txt na Name propriedade.For example, if you create two entries in a zip archive by using the CreateEntryFromFile method and provide NewEntry.txt as the name for the first entry and AddedFolder\\NewEntry.txt for the second entry, both entries will have NewEntry.txt in the Name property. A primeira entrada também terá NewEntry.txt na FullName propriedade, mas a segunda entrada terá AddedFolder\\NewEntry.txt na FullName propriedade.The first entry will also have NewEntry.txt in the FullName property, but the second entry will have AddedFolder\\NewEntry.txt in the FullName property.

ExemplosExamples

O exemplo a seguir mostra como recuperar entradas de um arquivo zip e avaliar as propriedades das entradas.The following example shows how to retrieve entries from a zip archive and evaluate the properties of the entries. Ele usa a Name propriedade para exibir o nome da entrada e as Length CompressedLength Propriedades e para calcular a quantidade de compactação do arquivo.It uses the Name property to display the name of the entry, and the Length and CompressedLength properties to calculate how much the file was compressed.

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

Aplica-se a