public class StackBasedIteration { static void Main(string[] args) { TraverseTree(args[0]); Console.WriteLine("Press key"); Console.ReadKey(); } public static void TraverseTree(string root) { Stack<string> dirs = new Stack<string>(20); if (!System.IO.Directory.Exists(root)) { throw new ArgumentException(); } dirs.Push(root); while (dirs.Count > 0) { string currentDir = dirs.Pop(); string[] subDirs; try { subDirs = System.IO.Directory.GetDirectories(currentDir); } catch (UnauthorizedAccessException e) { Console.WriteLine(e.Message); continue; } catch (System.IO.DirectoryNotFoundException e) { Console.WriteLine(e.Message); continue; } string[] files = null; try { files = System.IO.Directory.GetFiles(currentDir); } catch (UnauthorizedAccessException e) { Console.WriteLine(e.Message); continue; } catch (System.IO.DirectoryNotFoundException e) { Console.WriteLine(e.Message); continue; } foreach (string file in files) { try { System.IO.FileInfo fi = new System.IO.FileInfo(file); Console.WriteLine("{0}: {1}, {2}", fi.Name, fi.Length, fi.CreationTime); } catch (System.IO.FileNotFoundException e) { Console.WriteLine(e.Message); continue; } } foreach (string str in subDirs) dirs.Push(str); } } }
Standard input is empty
prog.cs(7,9): error CS0103: The name `Console' does not exist in the current context prog.cs(8,9): error CS0103: The name `Console' does not exist in the current context prog.cs(13,9): error CS0246: The type or namespace name `Stack' could not be found. Are you missing `System.Collections.Generic' using directive? prog.cs(17,23): error CS0246: The type or namespace name `ArgumentException' could not be found. Are you missing `System' using directive? prog.cs(19,9): error CS0841: A local variable `dirs' cannot be used before it is declared prog.cs(21,16): error CS0841: A local variable `dirs' cannot be used before it is declared prog.cs(23,33): error CS0841: A local variable `dirs' cannot be used before it is declared prog.cs(29,20): error CS0246: The type or namespace name `UnauthorizedAccessException' could not be found. Are you missing `System' using directive? prog.cs(36,17): error CS0103: The name `Console' does not exist in the current context prog.cs(46,20): error CS0246: The type or namespace name `UnauthorizedAccessException' could not be found. Are you missing `System' using directive? prog.cs(55,17): error CS0103: The name `Console' does not exist in the current context prog.cs(63,21): error CS0103: The name `Console' does not exist in the current context prog.cs(67,21): error CS0103: The name `Console' does not exist in the current context prog.cs(72,17): error CS0841: A local variable `dirs' cannot be used before it is declared Compilation failed: 14 error(s), 0 warnings
Standard output is empty