Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array CopyToMethod ..error 1

Status
Not open for further replies.

Programming2007

Programmer
Nov 10, 2006
24
US
Hello All I have 4 string arrays and I am trying to copy them all into 1 large array and have an error that the index is out of range.I thought of using an arraylist but then I would have subindexes for each of the add()'s which I am not sure how to manipulate.Below is my code which currently has the error array cannot be null. All I need to do is copy my 4 string arrays into 1 array and need help. How do I do that? Thanks in advance.

Dim curDirectoryHTM As String()
Dim curDirectoryASPX As String()
Dim aspxByDirectory As String()
Dim htmByDirectory As String()
Dim allFiles As String()
Dim dirs As String
Dim directories As String()
curDirectoryHTM = Directory.GetFiles("C:\SCoutline4", "*.htm")
curDirectoryASPX = Directory.GetFiles("C:\SCoutline4", "*.aspx")
curDirectoryASPX.CopyTo(allFiles, allFiles.Length)
curDirectoryHTM.CopyTo(allFiles, allFiles.Length)
directories = System.IO.Directory.GetDirectories("C:\SCoutline4")
Console.Write(dirs)
For Each dirs In directories
htmByDirectory = Directory.GetFiles(dirs, "*.htm")
aspxByDirectory = Directory.GetFiles(dirs, "*.aspx")
htmByDirectory.CopyTo(allFiles, allFiles.Length)
aspxByDirectory.CopyTo(allFiles, allFiles.Length)

Next dirs
'NEED TO COPY ALL 4 OF THESE ARRAYS TO ALLFILES ARRAY
Response.Write(allFiles))
 
this works

Code:
Dim curDirectoryexe As String()
        Dim curDirectorydll As String()
        Dim exeByDirectory As String()
        Dim dllByDirectory As String()
        Dim allFiles As String()
        Dim dirs As String
        Dim directories As String()
        curDirectoryexe = Directory.GetFiles("C:\windows", "*.exe")
        curDirectorydll = Directory.GetFiles("C:\windows", "*.dll")
        ReDim Preserve allFiles(curDirectoryexe.Length - 1)
        curDirectoryexe.CopyTo(allFiles, 0)
        ReDim Preserve allFiles(allFiles.Length + curDirectorydll.Length - 1)
        curDirectorydll.CopyTo(allFiles, curDirectoryexe.Length - 1)
        directories = System.IO.Directory.GetDirectories("C:\windows")
        For Each dirs In directories
            Dim previouslength As Integer = 0
            exeByDirectory = Directory.GetFiles(dirs, "*.exe")
            dllByDirectory = Directory.GetFiles(dirs, "*.dll")
            previouslength = allFiles.Length
            ReDim Preserve allFiles(allFiles.Length + exeByDirectory.Length - 1)
            exeByDirectory.CopyTo(allFiles, previouslength)
            previouslength = allFiles.Length
            ReDim Preserve allFiles(allFiles.Length + dllByDirectory.Length - 1)
            dllByDirectory.CopyTo(allFiles, previouslength)
        Next dirs
        For inttemp As Integer = 0 To 500
            TextBox1.Text &= allFiles(inttemp) & ControlChars.CrLf
        Next

Warning don't try this at home, it gave me 1809 hits. So it is very slow.

Christiaan Baes
Belgium

"My new site" - Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top