0

i tried to recursive all files in logical drive. i getting exception. how to exactly solve this? what the best to handle exception?

using System;
using System.IO;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = Directory.EnumerateFiles(@"c:\", "*", SearchOption.AllDirectories);

            try
            {
                if ((File.GetAttributes(@"c:\") & FileAttributes.ReparsePoint)
            != FileAttributes.ReparsePoint)
                {

                    foreach (string dir in list)
                    {

                        Console.WriteLine(dir);
                        Thread.Sleep(10);

                    }
                }
            }
            catch (UnauthorizedAccessException e) { Console.WriteLine(e); Console.ReadLine(); }
            }
        }
    }
Nichie
  • 1
  • 3
  • It seems that you are getting "Access is denied" exception which I believe, you need to have exception handling – Akash KC Oct 18 '17 at 02:13
  • @AkashKC how to handle this? i try to handle reparse points attribute. i edit my source code. – Nichie Oct 18 '17 at 02:27
  • Follow this https://stackoverflow.com/questions/172544/ignore-folders-files-when-directory-getfiles-is-denied-access – Akash KC Oct 18 '17 at 02:35
  • Possible duplicate of [Filter Attribute files Directory.EnumerateFiles System Hidden Reparse Points?](https://stackoverflow.com/questions/46802445/filter-attribute-files-directory-enumeratefiles-system-hidden-reparse-points) – wp78de Oct 21 '17 at 07:30

0 Answers0