|
-
Jul 23rd, 2009, 02:31 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Reading Files and Placing them in a Collection
I have created football (American) play creator. When the user is satisfied with a play he has created it is saved it as a file with a .play extension. What I want to do is to cycle through all the files in a folder (probably named after the team), and place each one that has the .play extension into a CList (of ClPlay) collection.
I have been able to successfully load one play at a time by using this code...
Code:
Dim fs As Stream = New FileStream(diaOpenPlay.FileName, FileMode.Open)
Dim bf As Runtime.Serialization.Formatters.Binary.BinaryFormatter = New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim Play As CLPlay
Play = CType(bf.Deserialize(fs), CLPlay)
...but that was when a specific play was selected from a load dialog box. This time I want to load all the plays in a folder and store it in a collection, and I'm not sure how to modify the above code to do that.
Thanks in advance.
Last edited by neef; Jul 23rd, 2009 at 07:04 PM.
Intermediate Level Programmer Extraordinaire 
-
Jul 23rd, 2009, 02:42 PM
#2
Re: Reading Files and Placing them in a Collection
Use System.IO.Directory.GetFiles("folder path here", "*.play") to get all the .play files into an array and then loop thru that array. Each string in the array is the full path to a .play file, so you use the same code you have for a single .play file (posted above) to create a CLPlay object and add that to the List(Of CLPLay) or a Dictionary(Of String, CLPLay). I prefer the Dictionary in this case because you can assign a name (key) to each CLPLay object so that later you can use that key to get to the coresponding CLPLay object.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 23rd, 2009, 07:00 PM
#3
Thread Starter
Hyperactive Member
Re: Reading Files and Placing them in a Collection
Totally nailed it. 
Thanks so much!
Intermediate Level Programmer Extraordinaire 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|