Imports System.IO
Imports System.IO.Compression
Module Module1
Sub Main()
Dim sourceFolder As String = "Path\To\Source\Folder"
Dim zipFilePath As String = "Path\To\Backup\Folder\backup.zip"
Dim password As String = "YourPassword"
' ایجاد فایل فشرده با پسورد
Using archive As ZipArchive = ZipFile.Open(zipFilePath, ZipArchiveMode.Create)
For Each file As String In Directory.GetFiles(sourceFolder)
Dim entry As ZipArchiveEntry = archive.CreateEntry(Path.GetFileName(file))
Using entryStream As Stream = entry.Open()
Using fileStream As FileStream = File.OpenRead(file)
fileStream.CopyTo(entryStream)
End Using
End Using
Next
' اعمال پسورد به فایل ZIP
archive.Encryption = EncryptionAlgorithm.PkzipWeak
archive.Password = password
End Using
' برای استخراج فایلها از فایل فشرده با پسورد
Using archive As ZipArchive = ZipFile.Open(zipFilePath, ZipArchiveMode.Read)
For Each entry As ZipArchiveEntry In archive.Entries
Dim destinationPath As String = Path.Combine(sourceFolder, entry.FullName)
entry.ExtractToFile(destinationPath, True)
Next
End Using
End Sub
End Module
پسورد مورد نظر خود را در متغیر password قرار بدید و پس از ایجاد فایل ZIP، پسورد به آن اعمال میشه. و با استفاده از متد ExtractToFile میتونید فایلها را از فایل ZIP با پسورد استخراج کنید.