title: C# How can I solve limitations when using DirectoryInfo?
body: <p>When I recursive through some folders and files, I encounter this error:</p>
  
  <p>The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directoryname must be less than 248 characters.</p>
  
  <p>Here's my function</p>
  
  <pre><code>private void ProcessDirectory(DirectoryInfo di)
  {
      try
      {
          DirectoryInfo[] diArr = di.GetDirectories();
  
          foreach (DirectoryInfo directoryInfo in diArr)
          {
              if (StopCheck)
                      return;
              ProcessDirectory(directoryInfo);
          }
          ProcessFile(di);
      }
      catch (Exception e)
      {
          listBoxError.Items.Add(e.Message);
      }
  
      TextBoxCurrentFolder.Text = di.ToString();
  }
  </code></pre>
  
  <p>I cannot make the directory names shorter, because I'm not allowed too so... How can I solve this problem?</p>
  
  <p><strong>Added:</strong>
  Here's the other function:</p>
  
  <pre><code>private void ProcessFile(DirectoryInfo di)
  {
      try
      {
          FileInfo[] fileInfo = di.GetFiles();
  
          if (fileInfo.LongLength != 0)
          {
              foreach (FileInfo info in fileInfo)
              {
                  Size += info.Length;
                  CountFile++;
              }
          }
      }
      catch (Exception e)
      {
          listBoxError.Items.Add(e.Message);
      }
  }
  </code></pre>
  
  <p><strong>EDIT</strong>
  Found this where he used Zeta Long Paths:
  <a href="https://stackoverflow.com/questions/1357358/how-can-i-use-fileinfo-class-avoiding-pathtoolongexception">How can I use FileInfo class, avoiding PathTooLongException?</a></p>
  
  <p>Have implemented it and now i'm going to let the program run over the night to see if it works.</p>
  
  <p><strong>EDIT</strong>
  Used the ZetaLongPath yesterday and it worked great! It even went through folders that needed permission access.</p>
  
  <p><strong>EDIT</strong>
  Instead of zetalongPath, I've used Delimon.Win32.IO.dll which i think is much better. It has the same interfaces as Win32.</p>