Reapz Posted December 15, 2002 Posted December 15, 2002 (edited) I'm having trouble popping elements out of a IO.FileSystemInfo array. I can't use the Remove method so I have to use the Clear method but I think I'm messing it up somewhere. Here is the section of code... Dim artistdir As New IO.DirectoryInfo(musicroot & "\" & dir.Name) Dim tracksArray As IO.FileSystemInfo() = artistdir.GetFiles Dim track As IO.FileInfo For Each track In tracksArray If track.Name = "Thumbs.db" Then Dim trackindex = tracksArray.IndexOf(tracksArray, track.Name) tracksArray.Clear(tracksArray, trackindex, 1) ElseIf track.Name = "Desktop.ini" Then Dim trackindex = tracksArray.IndexOf(tracksArray, track.Name) tracksArray.Clear(tracksArray, trackindex, 1) End If Next If tracksArray.Length <> 0 Then....... As you can see from the last line the subsequent code is dependent on these two files being removed from the array as they don't need to be considerd but even though the values match up the IndexOf method always returns -1. I've tried changing types and using the actual string instead of track.name in the IndexOf statement. I've just switched from VB6 and I'm still getting me head round .NET so any help would be great. Cheers! Edited December 15, 2002 by divil Quote I'm getting the hang of this now... No really I am!
*Gurus* divil Posted December 15, 2002 *Gurus* Posted December 15, 2002 You can't just remove items from an array. The clear method you are using is in fact a static method of the Array class and isn't appropriate. You need a collection-based class to be able to remove items like that. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Reapz Posted December 15, 2002 Author Posted December 15, 2002 Found a work around. More code and it looks a bit messy but it works! :D Quote I'm getting the hang of this now... No really I am!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.