SHARE
TWEET

Untitled

a guest Dec 16th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5.  
  6. namespace ConsoleApp1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             var path = @"C:\Users\sweisfel\source\repos\WordPressBackup";
  13.  
  14.             PrintDirRecursive(path);
  15.  
  16.             //PrintDirLoop(path);
  17.  
  18.             Console.ReadKey();
  19.         }
  20.  
  21.  
  22.         private static void PrintDirLoop(string root)
  23.         {
  24.             var folders = new Stack<string>();
  25.             folders.Push(root);
  26.  
  27.             while (folders.Count > 0)
  28.             {
  29.                 var currentFolder = folders.Pop();
  30.  
  31.                 foreach (var item in Directory.EnumerateFiles(currentFolder))
  32.                 {
  33.                     Console.WriteLine($"File: {item}");
  34.                 }
  35.  
  36.                 foreach (var item in Directory.EnumerateDirectories(currentFolder))
  37.                 {
  38.                     folders.Push(item);
  39.                 }
  40.             }
  41.  
  42.         }
  43.  
  44.  
  45.         private static void PrintDirRecursive(string path)
  46.         {
  47.             foreach (var item in Directory.EnumerateFiles(path))
  48.             {
  49.                 Console.WriteLine($"File: {item}");
  50.             }
  51.  
  52.             foreach (var item in Directory.EnumerateDirectories(path))
  53.             {
  54.                 PrintDirRecursive(item);
  55.             }
  56.         }
  57.  
  58.     }
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top