Reading from many files

student_help

Member
Joined
Aug 8, 2006
Messages
8
Programming Experience
Beginner
Hi

Would anyone be able to advise on a way that would allow a program to read from many files. I had this working for a single file but this is not acceptable for the progarm. I am trying to access the data which is stored in these files

The code i was using was
Dim FILE_NAME As String = "C:\Queue\" + "*.log" 'example file

Dim objReader As New System.IO.StreamReader(FILE_NAME)

* declares all the files in the folder
 
Need a bit more info here.

Do all the files have the same extension?
Will there ever be files added/removed?
How many files are we talking about here?
Do you want this to happen simultaineously?
 
System.IO got lots of classes and methods for you, here how to get all these files with *.log extension filter:
VB.NET:
Dim files() As String = IO.Directory.GetFiles("C:\Queue\", "*.log")
For Each FILE_NAME As String In files
  Dim objReader As New System.IO.StreamReader(FILE_NAME)
  '...
Next
 
Sorry

The files are all of the .log type and are all stored in the folder Queue which has been set as the File_Name "C:\Queue\" + "*.log

When the files are read they are to be deleted from the folder.
All this acts are to happen when a file arrives at the folder and a service is running. But at the moment when a button is pressed the data is extracted and placed into a sql server 2005 db
 
Ok, so JohnH's code below will do the reading for you. To delete a file you can use the following (i inlcuded a bit to check if the exists first, but you can omit that part if your posative the file will be there)

VB.NET:
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)

End If

Check out the FileSystemWatcher Class. It can raise an event if a file is added/modified etc in a folder.
 
Back
Top