So currently I am working on a program to backup files. What it does is search through each directory recursively like so:
Public Sub BackUp(ByVal root As String)
Dim FoundFile, FoundDirectory As String
'Loop thru each of the files in this directory
For Each FoundFile In My.Computer.FileSystem.GetFiles(root)
If (IO.File.GetAttributes(FoundFile) = IO.FileAttributes.Archive) Or RootCreated Then
ListBox1.Items.Add(FoundFile)
ListBox1.Update()
Dim FileName As String
FileName = RemoveSource(FoundFile, Source)
Try
IO.File.Copy(FoundFile, Destination & FileName)
Catch ex As Exception
Dim DestFile As String = Destination & FileName
Dim DestFileArr() As String = DestFile.Split("\")
Dim l As Integer
Dim folder As String
folder = DestFileArr(0)
For l = 1 To DestFileArr.GetUpperBound(0) - 1
folder = folder & "\" & DestFileArr(l)
If Not IO.Directory.Exists(folder) Then
IO.Directory.CreateDirectory(folder)
End If
Next
Try
IO.File.Copy(FoundFile, Destination & FileName)
Catch ex1 As Exception
MsgBox("Error:" & Chr(13) & ex1.Message & Chr(13) & " No Folder for the file to be placed in")
End Try
End Try
' IO.File.SetAttributes(FoundFile, IO.FileAttributes.Normal)
IO.File.SetCreationTime(Destination & FileName, IO.File.GetCreationTime(FoundFile))
IO.File.SetLastAccessTime(Destination & FileName, IO.File.GetLastAccessTime(FoundFile))
IO.File.SetAccessControl(Destination & FileName, IO.File.GetAccessControl(FoundFile))
IO.File.SetLastWriteTime(Destination & FileName, IO.File.GetLastWriteTime(FoundFile))
End If
Next
'Loop thru each directory in this directory
For Each FoundDirectory In My.Computer.FileSystem.GetDirectories(root)
'Give the user feedback about progress
'LabelSearch.Text = "Scanning: " & FoundDirectory
'LabelSearch.Update()
'Recursively call this very same sub procedure!
BackUp(FoundDirectory)
Next
End Sub
I have a problem after I hit about the 100th file, it "dies" and the compiler is like it's taking to long. It then asks me if I want to continue and I say yes. How do I stop that? I've tried GC.KeepAlive(me), for each file but that didn't seem to work. This is going to be used for directories that could possibly have over 100k files and I don't want to have to sit and hit yes every so many times.