ZipArchiveEntry.FullName Propriedade

Definição

Obtém o caminho relativo da entrada no arquivo zip.Gets the relative path of the entry in the zip archive.

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

Valor da propriedade

String

O caminho relativo da entrada no arquivo zip.The relative path of the entry in the zip archive.

Comentários

A FullName propriedade contém o caminho relativo, incluindo a hierarquia de subdiretório, de uma entrada em um arquivo zip.The FullName property contains the relative path, including the subdirectory hierarchy, of an entry in a zip archive. (Por outro lado, a Name propriedade contém apenas o nome da entrada e não inclui a hierarquia de subdiretórios.) 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.(In contrast, the Name property contains only the name of the entry and does not include the subdirectory hierarchy.) 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.

Você pode especificar qualquer cadeia de caracteres como o caminho de uma entrada, incluindo cadeias de caracteres que especificam caminhos absolutos e inválidos.You can specify any string as the path of an entry, including strings that specify invalid and absolute paths. Portanto, a FullName propriedade pode conter um valor que não esteja formatado corretamente.Therefore, the FullName property might contain a value that is not correctly formatted. Um caminho inválido ou absoluto pode resultar em uma exceção quando você extrai o conteúdo do arquivo zip.An invalid or absolute path might result in an exception when you extract the contents of the zip archive.

ExemplosExamples

O exemplo a seguir mostra como iterar o conteúdo de um arquivo. zip e extrair arquivos que contêm a extensão. txt.The following example shows how to iterate through the contents of a .zip file, and extract files that contain the .txt extension.

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

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

        Console.WriteLine("Provide path where to extract the zip file:");
        string extractPath = Console.ReadLine();

        // Normalizes the path.
        extractPath = Path.GetFullPath(extractPath);

        // Ensures that the last character on the extraction path
        // is the directory separator char.
        // Without this, a malicious zip file could try to traverse outside of the expected
        // extraction path.
        if (!extractPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
            extractPath += Path.DirectorySeparatorChar;

        using (ZipArchive archive = ZipFile.OpenRead(zipPath))
        {
            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
                {
                    // Gets the full path to ensure that relative segments are removed.
                    string destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName));

                    // Ordinal match is safest, case-sensitive volumes can be mounted within volumes that
                    // are case-insensitive.
                    if (destinationPath.StartsWith(extractPath, StringComparison.Ordinal))
                        entry.ExtractToFile(destinationPath);
                }
            }
        }
    }
}
Imports System.IO
Imports System.IO.Compression

Module Module1

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

        Console.WriteLine("Provide path where to extract the zip file:")
        Dim extractPath As String = Console.ReadLine()

        ' Normalizes the path.
        extractPath = Path.GetFullPath(extractPath)

        ' Ensures that the last character on the extraction path
        ' is the directory separator char. 
        ' Without this, a malicious zip file could try to traverse outside of the expected
        ' extraction path.
        If Not extractPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) Then
            extractPath += Path.DirectorySeparatorChar
        End If

        Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
            For Each entry As ZipArchiveEntry In archive.Entries
                If entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) Then

                    ' Gets the full path to ensure that relative segments are removed.
                    Dim destinationPath As String = Path.GetFullPath(Path.Combine(extractPath, entry.FullName))
                    
                    ' Ordinal match is safest, case-sensitive volumes can be mounted within volumes that
                    ' are case-insensitive.
                    If destinationPath.StartsWith(extractPath, StringComparison.Ordinal) Then 
                        entry.ExtractToFile(destinationPath)
                    End If

                End If
            Next
        End Using
    End Sub

End Module

Aplica-se a