Displaying copied file names in textbox

M

mmalinsky

I have the following code that I borrowed from this NG to copy files
from one location to another:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Const FOLDER_FROM As String = "D:\My Documents" ' Folder to
copy from
Const FOLDER_TO As String = "D:\My Documents\Miscellaneous2"
'Folder to create above folder in
Dim newDir As DirectoryInfo =
Directory.CreateDirectory(FOLDER_TO & "\" & New
DirectoryInfo(FOLDER_FROM).Name)
CopyFiles(New DirectoryInfo(FOLDER_FROM), newDir)
End Sub
Private Sub CopyFiles(ByVal FolderFrom As DirectoryInfo, ByVal
FolderTo As DirectoryInfo)
Dim Files() As String = Directory.GetFiles(FolderFrom.FullName)
Dim SF() As String =
Directory.GetDirectories(FolderFrom.FullName)
Dim Var As Integer
Dim start, finish As Double
For Var = Files.GetLowerBound(0) To Files.GetUpperBound(0)
File.Copy(Files(Var), FolderTo.FullName & "\" & New
FileInfo(Files(Var)).Name)
Next
For Var = SF.GetLowerBound(0) To SF.GetUpperBound(0)
Dim dName As String = New DirectoryInfo(SF(Var)).Name
Dim newD As New DirectoryInfo(FolderTo.FullName & "\" &
dName)
newD.Create()
CopyFiles(New DirectoryInfo(FolderFrom.FullName & "\" &
dName), newD)
Label2.Text = (Files(Var))
Label2.Refresh()
Next
End Sub

My question is why the line Label2.Text=(Files(Var)) does not work. I
get the following:

An unhandled exception of type 'System.IndexOutOfRangeException'
occurred in
update.exe

Additional information: Index was outside the bounds of the array.

TIA
Mike
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Because you are looping throught the SF array and are trying to access
an element in the Files array. The SF array has obviously fewer elements
than the Files array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top