|
-
November 8th, 2011, 09:41 PM
#1
Need streamreader to read content of multiple files
I can get streamreader to work on one file, but can't code right to get it to read multiple.
The first code is where I have it working fine. The second one just produces a dos window with no date.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace readtest
{
class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader("C:\\Users\Random.txt");
string str = sr.ReadLine();
string[] words = str.Split('|');
foreach (string word in words)
{
Console.WriteLine(word);
} Console.ReadKey();
}
}
}
This is the one I can't figure out what is wrong. No errors being produced, but not getting the result I want either.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string[] files = Directory.GetFiles("C:\\Users", ".txt");
foreach (string file in files)
{
StreamReader sr = new StreamReader(file);
string str = sr.ReadLine();
{
Console.WriteLine(file);
}
} Console.ReadKey();
}
}
}
-
November 8th, 2011, 09:43 PM
#2
Re: Need streamreader to read content of multiple files
I meant so say no "data" (not "date")
-
November 8th, 2011, 09:57 PM
#3
Re: Need streamreader to read content of multiple files
What happens when you put a breakpoint in the code and step through it?
-
November 8th, 2011, 10:29 PM
#4
Re: Need streamreader to read content of multiple files
I think you mean a wildcard "*.txt" rather than ".txt" in the Directory.GetFiles() function call.
Developing using:
.NET3.5 / VS 2010
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
|