I am trying to throw together a quick little program that will scan through my project folders and if any file in a given project has the archive attribute set then it should create a zip file containing all of the folders/files in that project. The code seems to be working but for some reason it is hanging at a certain point in the process.
Here is the relevant code
There are lots of folders to process and some of them have lots of files. For some reason it is creating the first 27 zip files just fine then hangs on the 28th folder. I can't see an issue with the code. The folder it is processing has 4 sub folders and a total of 205 files. Some of the ones processed before this have more and less folders as well as more and less files and some are bigger and some are smaller. The one that is hanging has a total size of just under 10mb but some of the ones that had no issue where over 100mb where a few were less than 1mb.
Any ideas?
Here is the relevant code
Code:
For Each cFolder As String In ChildFolders
ProgressBar2.Increment(1)
ProgressBar2.Refresh()
PathParts = cFolder.Split("\")
cFolderName = FolderName & "\" & PathParts(PathParts.Length - 1)
Label2.Text = "Project=" & PathParts(PathParts.Length - 1)
Label2.Refresh()
Me.Refresh()
If Not Directory.Exists(cFolderName) Then
Directory.CreateDirectory(cFolderName)
End If
For Each FileName As String In Directory.GetFiles(cFolder, "*.*", SearchOption.AllDirectories) 'Get Project Files
Me.Refresh()
If File.GetAttributes(FileName) And FileAttributes.Archive Then ' If any have archive flag
Using ZP1 As ZipFile = New ZipFile(cFolderName & "\" & PathParts(PathParts.Length - 1) & Format(Today, "yyMMdd") & ".zip")
ZP1.AddDirectory(cFolder)
ZP1.Save() 'This is where it is hanging
ZP1.Dispose()
End Using
Exit For
End If
Next
'For Each FileName As String In Directory.GetFiles(cFolder, "*.*", SearchOption.AllDirectories) 'Get Project Files
' Dim FA As Integer = File.GetAttributes(FileName)
' If FA And FileAttributes.Archive Then
' File.SetAttributes(FileName, FA And Not FileAttributes.Archive)
' End If
'Next
Next
Any ideas?