使用拖放复制文件 VB.Net

Copy a File Using DragDrop VB.Net

我的代码有什么问题?获取 'Process cannot access the file because it is being used by another process' error msg 有没有办法解决这个问题。我的 google-fu 并没有给我带来多少好运。我无法移动或复制,我会选择其中一个。

    Private Sub frmFiberTransMain_DragEnter(sender As Object, e As DragEventArgs) Handles MyBase.DragEnter
    If e.Data.GetDataPresent(DataFormats.FileDrop, False) = True Then
        e.Effect = DragDropEffects.All
    End If
End Sub

Private Sub frmFiberTransMain_DragDrop(sender As Object, e As DragEventArgs) Handles MyBase.DragDrop
    If e.Data.GetDataPresent(DataFormats.FileDrop) Then
        Dim filePaths As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
        Call CopyFileDrop(filePaths)
    End If
End Sub

Private Sub CopyFileDrop(filePaths As String())
    For Each fileLoc As String In filePaths
        Dim fileName As String = fileLoc
        Dim fi As New IO.FileInfo(fileName)
        File.Create(fileName)
        Dim justFileName As String = fi.Name
        Dim newPathName As String = gProgDir & "\" & justFileName
        Directory.Move(fileLoc, newPathName)            
    Next fileLoc
End Sub

File.Create(fileName) returns an open handle and you're not closing it. It doesn't look like you need that line. – @LarsTech 50 mins ago