「Product.15082012.txt」、「Product.16082012.txt」、「Service.15082012.txt」、「Service.16082012.txt」など、VB.NET で開発されたアプリケーションから日付ごとに作成されたログ ファイルがあります。 C:\ログ」. 作成されるログファイルの形式は、「Product.ddMMyyyy.txt」と「Service.ddMMyyyy.txt」です。
過去 6 か月間の "C:\Logs" フォルダー内のログ ファイルをループし、"C:\Logs\Archive" の下にある "archive.15082012.zip" および "archive.16082012.zip" のように圧縮する必要があります。別のアーカイブ アプリケーションを介して。
つまり、フォルダーをループしている間、製品とサービスを日付ごとに 1 つの zip ファイルに圧縮する必要があります。
どうやってやるの?ファイルを圧縮する方法は知っていますが、ファイルを日付ごとにピックアップして「Product.ddMMyyyy.txt」と「Service.ddMMyyyy.txt」をグループ化する方法がわかりません
Private Sub AddToArchive(ByVal zip As Package, ByVal fileToAdd As String)
'Replace spaces with an underscore (_)
Dim uriFileName As String = fileToAdd.Replace(" ", "_")
'A Uri always starts with a forward slash "/"
Dim zipUri As String = String.Concat("/", _
IO.Path.GetFileName(uriFileName))
Dim partUri As New Uri(zipUri, UriKind.Relative)
Dim contentType As String = _
Net.Mime.MediaTypeNames.Application.Zip
'The PackagePart contains the information:
' Where to extract the file when it's extracted (partUri)
' The type of content stream (MIME type): (contentType)
' The type of compression: (CompressionOption.Normal)
Dim pkgPart As PackagePart = zip.CreatePart(partUri, _
contentType, CompressionOption.Normal)
'Read all of the bytes from the file to add to the zip file
Dim bites As Byte() = File.ReadAllBytes(fileToAdd)
'Compress and write the bytes to the zip file
pkgPart.GetStream().Write(bites, 0, bites.Length)
End Sub