Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enumerate files + folders recursively with System.IO.Directory.GetFiles

How can I change this code to also enumerate sub directories?

var fqFilenames= new List<String>(System.IO.Directory.GetFiles(sMappedPath));
var filenames= fqFilenames.ConvertAll((s) => { return s.Replace(sMappedPath+"\\", ""); });
FileListView.DataSource = filenames;
like image 590
Tom Avatar asked Nov 28 '22 05:11

Tom


2 Answers

Can you just use Directory.GetFiles(string, string, SearchOption)? If not, please explain what you need which that doesn't cover.

For example:

Directory.GetFiles(sMappedPath, "*", SearchOption.AllDirectories)
like image 157
Jon Skeet Avatar answered Dec 15 '22 14:12

Jon Skeet


Try looking at Directory.GetDirectories or the DirectoryInfo equivalent. The example on the linked page shows recursively traversing subdirectories

like image 43
Gishu Avatar answered Dec 15 '22 15:12

Gishu