Created
December 3, 2015 01:05
-
-
Save vicsstar/4fc135360c1447e1e07f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.IO; | |
class FileListings { | |
public void ListFiles() { | |
var directory = new System.IO.DriveInfo(@"C:\").RootDirectory; | |
var folders = new Stack<DirectoryInfo>(); | |
var files = new Stack<FileInfo>(); | |
folders.Push(directory); | |
while (folders.Count != 0) { | |
var poppedFolder = folders.Pop(); | |
if (poppedFolder.Exists) { | |
var __folders = poppedFolder.GetDirectories(); | |
var __files = poppedFolder.GetFiles(); | |
// push all the folders into our folder list. | |
foreach(var folder in __folders) { | |
// push the new folder into our list of folders. | |
folders.Push(folder); | |
} | |
// push all the files into our file list. | |
foreach(var file in __files) { | |
// push the file into our list of files. | |
files.Push(file); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment