所以我有两个需要帮助的功能。使用DotNetZip检查zip文件
Public Function checkZipForFiles(ByVal zipFilepath As String)
Try
Dim doc As New System.Xml.XmlDocument
If My.Computer.FileSystem.FileExists("Backup.xml") Then
doc.Load("Backup.xml")
Dim JobNodes As XmlNodeList = doc.GetElementsByTagName("Job")
For Each JobNode In JobNodes
Dim Source = JobNode.SelectNodes("Source")
For Each item As System.Xml.XmlNode In Source
For Each File In checkFilesInFolder(item.InnerText)
Using zip = ZipFile.Read(zipFilepath)
Dim fileName As String
fileName = checkFilesInFolder(item.InnerText)
Dim e As ZipEntry = zip(fileName)
If e Is Nothing Then
Console.WriteLine("File: " & fileName & " does not exist in zip.")
End If
End Using
Next
Next
Next
End If
Catch ex As Exception
Console.Error.WriteLine(ex.Message)
myLogger.Log(ex.Message)
End Try
End Function
这个读入一个xml文件。 xml文件存储压缩过程的信息,例如“目标”,“文件源”和“作业名称”。我想要这个函数检查压缩文件,看看是否所有的文件都在压缩文件中。正如你所看到的,这个函数需要借助“checkFilesiInFolder”函数来获取要在zip中搜索的文件名。
问题 - 我只返回在“checkFilesInFolder”函数中扫描的最后一个文件。
Public Function checkFilesInFolder(ByVal folderPath As String)
Try
' make a reference to a directory
Dim di As New IO.DirectoryInfo(folderPath)
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim file As IO.FileInfo
Console.WriteLine("The following files are located in " & folderPath)
'list the names of all files in the specified directory
For Each file In diar1
Console.WriteLine(file.FullName)
'myLogger.Log(file.ToString)
Next
Return file.ToString
Catch ex As Exception
Console.Error.WriteLine(ex.Message)
myLogger.Log(ex.Message)
End Try
End Function