Skip to content

Instantly share code, notes, and snippets.

@vicsstar
Created December 3, 2015 01:05
Show Gist options
  • Save vicsstar/4fc135360c1447e1e07f to your computer and use it in GitHub Desktop.
Save vicsstar/4fc135360c1447e1e07f to your computer and use it in GitHub Desktop.
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