Esempio n. 1
0
        public static void Walk(DirectoryInfo di, WalkFunction f)
        {
            FileInfo[] files = null;
            try
            {
                files = di.GetFiles("*.*");
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
                return;
            }
            if (files != null)
            {
                foreach (var fi in files)
                {
                    // In this example, we only access the existing FileInfo object. If we
                    // want to open, delete or modify the file, then
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to TraverseTree().
                    f(fi);
                }
            }

            // Now find all the subdirectories under this directory.
            foreach (var dirInfo in di.GetDirectories())
            {
                if (!dirInfo.Name.ToLowerInvariant().Equals(".svn"))
                {
                    Walk(dirInfo, f);
                }
            }
        }
Esempio n. 2
0
 public static void Walk(FileInfo fi, WalkFunction f)
 {
     f(fi);
 }
Esempio n. 3
0
 public static void Walk(string dir, WalkFunction f)
 {
     Walk(new DirectoryInfo(dir), f);
 }