Reputation:
{
DirectoryInfo dinfo = new DirectoryInfo(@"C:\Documents and Settings\g\Desktop\123");
FileInfo[] Files = dinfo.GetFiles("*.txt");
foreach (FileInfo filex in Files)
{
string contents = File.ReadAllText(filex);
string sharename = Regex.Match(contents, @"\Share+(\S*)(.)(.*)(.)").Groups[2].Value;
}
}
I just want to be able to open each textfile in this directory, read it all, and then pull the regex i have listed, With this code can someone point out where my brain fart is?
The best overloaded method match for 'System.IO.File.FileInfo' to 'string' has some invalid arguments Argument '1' cannot convert frm System.IO.FileInfo to string
Upvotes: 4
Views: 16805
Reputation: 37533
File.ReadAllText does not accept FileInfo as a parameter. Use instead:
String contents = File.ReadAllText(filex.FullName);
Upvotes: 0
Reputation: 1038730
The ReadAllText method expects a filename argument of type string and not FileInfo:
string contents = File.ReadAllText(filex.FullName);
Upvotes: 28