我有以下循环,它适用于移动文件部分
For Each foundFile As String In My.Computer.FileSystem.GetFiles(dir, FileIO.SearchOption.SearchTopLevelOnly, "*.csv")
''If (Not String.IsNullOrEmpty(lastFile)) Then
''File.Move(Path.GetFullPath(lastFile), (dir + "/processed/"))
''End If
Dim oTimer As New System.Diagnostics.Stopwatch
oTimer.Start()
Dim tblName = Path.GetFileNameWithoutExtension(foundFile)
Dim numbers() As Char = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
tblName = tblName.TrimEnd(numbers)
''analyze table name, call method for either insert or append
cmd.Parameters.Add(New SqlParameter("@tblName", tblName))
''this command should check the table to exist first, but need to add if
cmd.ExecuteNonQuery()
retRecCnt += insertRows(conString, foundFile, tblName)
cmd.Parameters.Clear()
lastFile = foundFile
''
Next
将CSV文件正确导出到数据库表并移至下一个文件。但是当调用move命令时,我收到以下错误:
System.IO.IOException was unhandled
HResult=-2147024864
Message=The process cannot access the file because it is being used by another process.
Source=mscorlib