Thanks to Baldrick for the valuable comment. using this eventually solved the problem. There may be other ways, but that's how I ended up.
private void Walkdirectoryfulldepth(string dirPath, List<string> data) { DirectoryInfo dirInfo = new DirectoryInfo(dirPath); var sorted = dirInfo.GetDirectories("*.*", SearchOption.TopDirectoryOnly).ToList(); DirectoryInfo[] subDirs = dirInfo.GetDirectories("*.*", SearchOption.TopDirectoryOnly); string[] strDir=new string[subDirs.Count()]; int i =0; foreach (var item in subDirs) { strDir[i] = item.FullName; i++; } NumericComparer nc = new NumericComparer(); Array.Sort(strDir, nc); foreach (var item in strDir) { data.Add(Path.GetFileName(item)); Walkdirectoryfulldepth(item, data); }
Get the below class from codeproject , implemented similarly to the StrCmpLogicalW logical sorting in the Windows Explorer API.
NumericComparer StringLogicalComparer
source share