item -> will hold the whole directory so, doing toString isn't the option if you want the Name of Folder/SubFolder only
see there is method "Name" which you can use it by calling as item.Name in console.WriteLine() , instead of item.toString()
foreach (var item in Dirs)
{
Console.WriteLine("The folders:{0}", item.Name());
}
or you can do this : Getting the folder name from a path
I would probably use something like:
string path = "C:/folder1/folder2/file.txt";
string lastFolderName = Path.GetFileName( Path.GetDirectoryName( path ) );
The inner call to GetDirectoryName will return the full path, while the outer call to GetFileName() will return the last path component - which will be the folder name.
This approach works whether or not the path actually exists. This approach, does however, rely on the path initially ending in a filename. If it's unknown whether the path ends in a filename or folder name - then it requires that you check the actual path to see if a file/folder exists at the location first.