Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- var path = @"C:\Users\sweisfel\source\repos\WordPressBackup";
- PrintDirRecursive(path);
- //PrintDirLoop(path);
- Console.ReadKey();
- }
- private static void PrintDirLoop(string root)
- {
- var folders = new Stack<string>();
- folders.Push(root);
- while (folders.Count > 0)
- {
- var currentFolder = folders.Pop();
- foreach (var item in Directory.EnumerateFiles(currentFolder))
- {
- Console.WriteLine($"File: {item}");
- }
- foreach (var item in Directory.EnumerateDirectories(currentFolder))
- {
- folders.Push(item);
- }
- }
- }
- private static void PrintDirRecursive(string path)
- {
- foreach (var item in Directory.EnumerateFiles(path))
- {
- Console.WriteLine($"File: {item}");
- }
- foreach (var item in Directory.EnumerateDirectories(path))
- {
- PrintDirRecursive(item);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment