title: Dispose FileInfo()
body: <pre><code> Dim FolderName As New IO.DirectoryInfo(FileLocationFolder)
   Dim diar1 As IO.FileInfo() = FolderName.GetFiles("*.xml")
  </code></pre>
  
  <p>I am looping through diar1 like the following</p>
  
  <pre><code> For Each CurrFile In diar1
   Next 
  </code></pre>
  
  <p>Does that lock all the files in that directory?</p>
  
  <p>If so, how do I dispose it after I am done? Any help would be appreciated.</p>
  
  <p>Here is the rest of my code:</p>
  
  <pre><code>Public Sub Get_FTP_video(ByVal curr As Integer)
      Try
  
          Dim FolderName As New IO.DirectoryInfo(FileLocationFolder)
          Dim diar1 As IO.FileInfo() = FolderName.GetFiles("*.xml")
  
          Dim CurrFile As IO.FileInfo
          Dim CurrfileName As String
          Dim currsize, MinSize As Integer
          currsize = 0
          MinSize = 0
  
          For Each CurrFile In diar1
              CurrfileName = CurrFile.Name
  
              If CurrFile.CreationTime.Date = Today.Date Then
                  GET_FileName(FileLocationFolder &amp; CurrfileName, currsize)
                  If MinSize = 0 Then
                      MinSize = currsize
                  Else
                      If currsize &lt; MinSize Then
                          splitter = CurrFile.Name.Split(".")
                          If My.Computer.FileSystem.FileExists(FileLocationFolder &amp; splitter(0).ToString &amp; ".mp4") Then
                              MinSize = currsize
                              newVideoName = splitter(0).ToString
                          End If
                      End If
                  End If
              End If
          Next
  
          System.IO.File.Move(FileLocationFolder &amp; videonamee &amp; ".mp4", MoveFileToFolder &amp; videonamee)
          sendmessage = True
  
          MoveAllFilesToBin()
  
       Catch ex As System.Data.SqlClient.SqlException
       Catch ex As Exception 
       End Try
  End Sub
  </code></pre>
  
  <p>'</p>
  
  <pre><code>Public Sub GET_FileName(ByVal directorytracer As String, ByRef fileSize As Integer)
          Try
              Dim xmldoc As New XmlDataDocument()
              Dim mmm As New XmlDataDocument
              Dim xmlnode As XmlNodeList
              Dim i As Integer
              Dim str As String
              Dim fs As New FileStream(directorytracer, FileMode.Open, FileAccess.Read)
              xmldoc.Load(fs)
              Dim ds As New DataSet
              Dim xmlNodeRdr As XmlNodeReader
              xmlnode = xmldoc.GetElementsByTagName("item")
  
              For i = 0 To xmlnode.Count - 1
                  str = xmlnode(i).ChildNodes.Item(3).InnerXml
                  mmm.InnerXml = str
                  xmlNodeRdr = New XmlNodeReader(mmm)
                  ds.ReadXml(xmlNodeRdr)
                  fileSize = CInt(ds.Tables(0).Rows(0).Item(0).ToString)
              Next
  
          Catch ex As System.Data.SqlClient.SqlException
  
          Catch ex As Exception
  
          End Try
  
      End Sub
  </code></pre>
  
  <p>.</p>
  
  <p>The error occurs in this function:</p>
  
  <pre><code>Sub MoveAllFilesToBin()
      Try
          Dim FolderName As New IO.DirectoryInfo(FileLocationFolder)
          Dim diar1 As IO.FileInfo() = FolderName.GetFiles()
          For Each CurrFile In diar1
              If System.IO.File.Exists(BinFolderFTP &amp; CurrFile.Name) Then
                  System.IO.File.Delete(BinFolderFTP &amp; CurrFile.Name)
              End If
              System.IO.File.Move(FileLocationFolder &amp; CurrFile.Name, BinFolderFTP &amp; CurrFile.Name)
          Next
  
          Catch ex As System.Data.SqlClient.SqlException
          Catch ex As Exception
      End Try
  End Sub
  </code></pre>
  
  <p>.</p>
  
  <pre><code>The process cannot access the file because it is being used by another process.
     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.__Error.WinIOError()
     at System.IO.File.Move(String sourceFileName, String destFileName)
  </code></pre>