/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/snippets/visualbasic/VS_Snippets_CLR_System/system.io.compression.ziparchive/vb/program1.vb
43 строки
2 KB
Next Turn
Format codes based on .editorconfig, Part 15 (#18959)
16 июн 2020, 14:56
Не верифицирован
16 июн 2020, 14:56
2eb0af2
Код
Авторство
О чём код?
' <snippet1> 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 ' </snippet1>