J
Jim in Arizona
I've looked around the web but can't find anything to help me out.
I was able to get some code to move some files from one directory to
another, which works fine:
====================================
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim SourceDir As String = "C:\test\"
Dim DestinationDir As String = "\\server1\share\test\"
Dim f() As String = System.IO.Directory.GetFiles(SourceDir)
For i As Integer = 0 To UBound(f)
System.IO.File.Move(f(i), DestinationDir & "\" &
FileNameWithoutThePath(f(i)))
Next i
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Critical, "Error!")
End Try
End Sub
Public Function FileNameWithoutThePath(ByVal b As String) As String
Dim j As Int16
j = Convert.ToInt16(b.LastIndexOf("\"))
Return b.Substring(j + 1)
End Function
====================================
The problem I run into is when the file already exists in the destination
directory or if the file it's trying to move is in use (locked) and error
occurs. I need to be able to skip the problem file and move on to the next
file to be moved. I have tried various things like incrementing i (i = i +1)
in various parts of the code but this hasn't worked.
Any assistance or direction would be appreciated!
TIA,
Jim
I was able to get some code to move some files from one directory to
another, which works fine:
====================================
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim SourceDir As String = "C:\test\"
Dim DestinationDir As String = "\\server1\share\test\"
Dim f() As String = System.IO.Directory.GetFiles(SourceDir)
For i As Integer = 0 To UBound(f)
System.IO.File.Move(f(i), DestinationDir & "\" &
FileNameWithoutThePath(f(i)))
Next i
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Critical, "Error!")
End Try
End Sub
Public Function FileNameWithoutThePath(ByVal b As String) As String
Dim j As Int16
j = Convert.ToInt16(b.LastIndexOf("\"))
Return b.Substring(j + 1)
End Function
====================================
The problem I run into is when the file already exists in the destination
directory or if the file it's trying to move is in use (locked) and error
occurs. I need to be able to skip the problem file and move on to the next
file to be moved. I have tried various things like incrementing i (i = i +1)
in various parts of the code but this hasn't worked.
Any assistance or direction would be appreciated!
TIA,
Jim