|
-
August 20th, 2009, 02:53 AM
#1
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);
}
}
/*
-
August 20th, 2009, 04:06 AM
#2
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)
-
August 20th, 2009, 04:47 AM
#3
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..
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
August 20th, 2009, 06:05 AM
#4
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!
-
August 20th, 2009, 08:14 PM
#5
Re: File.ReadAllLines Question
 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.
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
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
|