PathTooLongException problem/question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justin

    PathTooLongException problem/question

    Hi. I'm writing a little c# program to list all the files in a
    selected directory longer than a given size. The problem is that when
    it finds a file that is too long for Windows, I get the
    PathTooLongExce ption error. I try to handle the exception, but can't
    do anything because, well, the file is too long. I can see what and
    where the offending file is in the Locals window, so .NET can obviously
    read the file path, but I can't write that to any variable. Any
    suggestions? (And how certain files that are too long get there in the
    first place is another question for another day...) Following is an
    outline of my code:

    * user selects a directory from a treeview
    * code calls the AddFilesToList method which iterates through the files
    in the chosen directory
    * when files are longer than e.g. 100 characters the file name is
    written to an arraylist
    * the subfolders of the chosen directory are iterated through each
    recursively calling AddFilesToList

    And the AddFilesToList method. (For some reason the spaces at the
    start of lines aren't coming out, so I hope this is worth something.)
    private void AddFilesToList( DirectoryInfo dir)
    {
    FileInfo[] files = dir.GetFiles();
    DirectoryInfo[] subdirs = dir.GetDirector ies();

    foreach(FileInf o fi in files)
    {
    try
    {
    if(fi.FullName. Length >
    Convert.ToInt32 (txtFileLengthC utoff.Text))
    {
    Debug.WriteLine ("try file: " + fi.FullName);
    longFiles.Add(f i.FullName); // this is the arraylist
    }
    }
    catch (System.IO.Path TooLongExceptio n e)
    {
    Debug.WriteLine ("catch file: " + fi.FullName);
    // string temp = fi.DirectoryNam e;
    // temp = fi.FullName;

    longFiles.Add(f i.FullName);
    }
    }
    foreach (DirectoryInfo di in subdirs)
    {
    AddFilesToList( di);
    }
    }


    Thanks for any help,
    Justin

  • Chris R. Timmons

    #2
    Re: PathTooLongExce ption problem/question

    Justin,



    You may want to explore the data captured in the PathTooLongExce ption
    instance. There are several properties, including InnerMessage, that
    may shed more light on what's going wrong.

    --
    Hope this helps.

    Chris.
    -------------
    C.R. Timmons Consulting, Inc.

    Comment

    • Chris R. Timmons

      #3
      Re: PathTooLongExce ption problem/question

      Justin,



      You may want to explore the data captured in the PathTooLongExce ption
      instance. There are several properties, including InnerMessage, that
      may shed more light on what's going wrong.

      --
      Hope this helps.

      Chris.
      -------------
      C.R. Timmons Consulting, Inc.

      Comment

      • Justin

        #4
        Re: PathTooLongExce ption problem/question

        Thanks Chris. I had tried exploring the PathTooLongExce ption, but
        didn't find anything useful. The e.Message gives the same message that
        prints out, and the InnerException gives nothing because it's null. I
        know the information exists somewhere because as I said, I can see the
        offending file in the Locals window as I'm debugging the code. Thanks
        for the reply.
        Justin

        Comment

        • Justin

          #5
          Re: PathTooLongExce ption problem/question

          Thanks Chris. I had tried exploring the PathTooLongExce ption, but
          didn't find anything useful. The e.Message gives the same message that
          prints out, and the InnerException gives nothing because it's null. I
          know the information exists somewhere because as I said, I can see the
          offending file in the Locals window as I'm debugging the code. Thanks
          for the reply.
          Justin

          Comment

          Working...