I am looping through a directory and performing these actions on every file:
1. Getting the file's information via fileInfo
2. Grabbing data from MS SQL and making a dataTable
3. Reading the files via a streamReader
4. moving the file to another directory
5. Adding this a record with the file information to MS SQL
For 99% of the files this works fine. For 1 or 2 files (out of 100) the files are not moved. I put a try/catch around the move operation and output the error and this is what I get:
System.IO.IOException: The process cannot access the file "U:\UPSDBS\PAPRLESS\review\CB1\prnt1.R21845HP.J0062752.085847aq0000.txt" because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.File.Move(String sourceFileName, String destFileName)
at PreProcessor.MainForm.ProcessReport(String filePath) in D:\Documents and Settings\dbb8fnd\My Documents\Visual Studio Projects\Infrastructure\Infrastructure4.6\MainForm.vb:line 631
I put a while around the move operation:
Dim moveFile = True
While (moveFile = True)
Try
System.IO.File.Move(sourceDir, destDir)
moveFile = False
Catch
moveFile = True
End Try
End While
and all the files are moved OK.
At first I thought that the file sizes were causing the problem but the file sizes (of those that are not being moved) are much smaller than many others that are moved over.
Question:
I don't understand why only 99% of the files are moved over without the While? Where am I going wrong?
Thanx
1. Getting the file's information via fileInfo
2. Grabbing data from MS SQL and making a dataTable
3. Reading the files via a streamReader
4. moving the file to another directory
5. Adding this a record with the file information to MS SQL
For 99% of the files this works fine. For 1 or 2 files (out of 100) the files are not moved. I put a try/catch around the move operation and output the error and this is what I get:
System.IO.IOException: The process cannot access the file "U:\UPSDBS\PAPRLESS\review\CB1\prnt1.R21845HP.J0062752.085847aq0000.txt" because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.File.Move(String sourceFileName, String destFileName)
at PreProcessor.MainForm.ProcessReport(String filePath) in D:\Documents and Settings\dbb8fnd\My Documents\Visual Studio Projects\Infrastructure\Infrastructure4.6\MainForm.vb:line 631
I put a while around the move operation:
Dim moveFile = True
While (moveFile = True)
Try
System.IO.File.Move(sourceDir, destDir)
moveFile = False
Catch
moveFile = True
End Try
End While
and all the files are moved OK.
At first I thought that the file sizes were causing the problem but the file sizes (of those that are not being moved) are much smaller than many others that are moved over.
Question:
I don't understand why only 99% of the files are moved over without the While? Where am I going wrong?
Thanx