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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Try
Dim SourceDir As String = "C:\test\"
Dim DestinationDir As String = "\\server1\shar e\test\"
Dim f() As String = System.IO.Direc tory.GetFiles(S ourceDir)
For i As Integer = 0 To UBound(f)
System.IO.File. Move(f(i), DestinationDir & "\" &
FileNameWithout ThePath(f(i)))
Next i
Catch ex As Exception
MsgBox(ex.Messa ge.ToString, MsgBoxStyle.Cri tical, "Error!")
End Try
End Sub
Public Function FileNameWithout ThePath(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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Try
Dim SourceDir As String = "C:\test\"
Dim DestinationDir As String = "\\server1\shar e\test\"
Dim f() As String = System.IO.Direc tory.GetFiles(S ourceDir)
For i As Integer = 0 To UBound(f)
System.IO.File. Move(f(i), DestinationDir & "\" &
FileNameWithout ThePath(f(i)))
Next i
Catch ex As Exception
MsgBox(ex.Messa ge.ToString, MsgBoxStyle.Cri tical, "Error!")
End Try
End Sub
Public Function FileNameWithout ThePath(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
Comment