ZipArchive.Entries 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 ZIP 아카이브에 있는 항목의 컬렉션을 가져옵니다.
public:
property System::Collections::ObjectModel::ReadOnlyCollection<System::IO::Compression::ZipArchiveEntry ^> ^ Entries { System::Collections::ObjectModel::ReadOnlyCollection<System::IO::Compression::ZipArchiveEntry ^> ^ get(); };
public System.Collections.ObjectModel.ReadOnlyCollection<System.IO.Compression.ZipArchiveEntry> Entries { get; }
member this.Entries : System.Collections.ObjectModel.ReadOnlyCollection<System.IO.Compression.ZipArchiveEntry>
Public ReadOnly Property Entries As ReadOnlyCollection(Of ZipArchiveEntry)
속성 값
현재 zip 보관 위치에 있는 항목의 컬렉션입니다.
예외
zip 보관 위치가 읽기를 지원하지 않는 경우
zip 보관 위치가 삭제되었습니다.
zip 보관 위치가 손상되었으므로 해당 항목을 검색할 수 없습니다.
예제
다음 예제에서는 zip 보관 파일을 열고 항목 컬렉션을 반복하는 방법을 보여줍니다.
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);
}
}
}
}
}
open System
open System.IO;
open System.IO.Compression;
[<EntryPoint>]
let main _ =
let zipPath = @".\result.zip"
printfn "Provide path where to extract the zip file:"
let extractPath = stdin.ReadLine();
// Normalizes the path.
let mutable 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) |> not then
extractPath <- extractPath + string Path.DirectorySeparatorChar
use archive = ZipFile.OpenRead zipPath
for entry in archive.Entries do
if entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) then
// Gets the full path to ensure that relative segments are removed.
let 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) then
entry.ExtractToFile destinationPath
0
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
설명
사용 된 항목의 Entries 전체 컬렉션을 검색 하는 속성입니다. 메서드를 GetEntry 사용하여 이름으로 단일 항목을 검색합니다.
적용 대상
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET