The first code works, however I need to be able to read contents of multiple files from a particular directory. Start simple and build from there I figure. Doing something wrong somewhere, as the 2nd code only brings up the dos window without any data.
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 need to have working. I must be structuring something wrong. I've tried different ways, but no luck.
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();
}
}
}