我有一個邏輯問題,只需要更多的工作就可以了。DotNetZip循環邏輯的邏輯幫助
For Each JobNode In JobNodes
Dim Source = JobNode.SelectNodes("Source")
For Each item As System.Xml.XmlNode In Source
Dim infoReader As System.IO.FileInfo
''''Discerns whether a file or directory
If item.InnerText.Contains(".") Then 'is a file
If Dir$(item.InnerText) <> vbNullString Then
mySize += FileLen(item.InnerText)
End If
zip.AddFile(item.InnerText, "")
Dim numFiles2 = filenames.Count
mySize = BytesTO(mySize, convTo.MB)
Console.WriteLine("...Added all " & numFiles2 & " files. Total loose file collection size is " & Math.Round(mySize, 2) & " MB")
Console.WriteLine(vbCrLf)
Else 'is a directory
zip.AddDirectory(item.InnerText, GetLastDirName(item.InnerText & " "))
Dim dinfo As New DirectoryInfo(item.InnerText)
Dim sizeOfDir As Long = DirectorySize(dinfo, True)
Dim numFiles As Integer = CountFiles_FolderAndSubFolders(item.InnerText)
Console.WriteLine("...Added all " & numFiles & " files. Total directory size is {0:N2} MB", (CDbl(sizeOfDir))/(1024 * 1024))
Console.WriteLine(vbCrLf)
End If
Next
這是我製作的備份程序的一部分。這是確定要添加到zip的對象是文件(IF語句的第一部分)還是目錄(IF語句的ELSE部分)的部分。
我的問題是,我試圖添加以下代碼:
Dim numFiles2 = filenames.Count
mySize = BytesTO(mySize, convTo.MB)
Console.WriteLine("...Added all " & numFiles2 & " files. Total loose file collection size is " & Math.Round(mySize, 2) & " MB")
Console.WriteLine(vbCrLf)
就在zip.AddFile(item.innertext,"")
部分之後。我想添加這個,這樣我就可以從控制檯打印出這些信息。
問題是,如果我只是把它放在zip.addfile()
之後,它會直接在每次上面輸出代碼。我只希望它打印出來的那部分(正上方),一旦完成將所有鬆散的文件(或文件添加使用zip.AddFile()
)
編輯:添加在頂環更多的澄清
有一件事可能會改變這是我使用For語句的事實。檢查上面的編輯 – MaylorTaylor 2013-03-22 19:06:36
其實這正是我以爲你可能會這樣做。在內部循環之後,您可以將我的答案的「循環迭代」部分添加到外部循環的主體中。 – 2013-03-22 19:09:00
完成了。謝謝先生。我從來不需要做那樣的事情,但它總是有意義的。 – MaylorTaylor 2013-03-22 19:16:18