File.ReadAllLines Question
I have the following that i'm tryingto search one directory and all files with a string value below. The problem is that it keeps returning that it could 'Could not find file 'U:\System.IO.FileInfo[]'.'. The string directory does exist as a valid path. any ideas?
/*
string logdir = (string)Key.GetValue("LogDirectory");
string directory = logdir;
DirectoryInfo dirinfo = new DirectoryInfo(directory);
System.IO.FileInfo[] files = dirinfo.GetFiles("*.txt");
foreach (FileInfo fi in files)
{
sw.WriteLine(fi.Name, fi.Extension);
foreach (string line in File.ReadAllLines(files.ToString()))
{
if (line.Contains("crap"))
sw.WriteLine(fi + "contains" + line.ToString() + Environment.NewLine);
}
}
/*
Re: File.ReadAllLines Question
The message looks clear to me, the filename does not exists.
your error
Code:
string line in File.ReadAllLines(files.ToString())
change it to
Code:
string line in File.ReadAllLines(fi.FullName)
Re: File.ReadAllLines Question
Yes, don't assume (and I have before on many occasions) that you know what "someObject.ToString();" will return. As Danny has correctly pointed out..
Re: File.ReadAllLines Question
go i'm such an idiot. i did use FullName but like a method for some stupid reason!
Thank guys..yea i know it was a stupid question!
Re: File.ReadAllLines Question
Quote:
Originally Posted by
stevetaylor15
go i'm such an idiot.
Remember Kaa's Law. In a group of N people, most are idiots. For sufficiently large vales of N. ;)