CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2009
    Posts
    4

    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);
    }

    }
    /*

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    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)

  3. #3
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    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.......

  4. #4
    Join Date
    Aug 2009
    Posts
    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!

  5. #5
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: File.ReadAllLines Question

    Quote Originally Posted by stevetaylor15 View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured