C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » File Operations »

Directory Tree view


Posted Date: 19 Aug 2009    Resource Type: Code Snippets    Category: File Operations
Author: Shunmuganathan MMember Level: Diamond    
Rating: 1 out of 5Points: 8



Description :


Following code is used to prints the directory name and retrieves
its children in treeview

Used Name Spaces

using System;
using System.IO;



Code Segment

public class Example15_8
{

public static void ShowDirectory(DirectoryInfo di, int intLevel)
{
try
{
string MystrPad = new String(' ', 2*intLevel);
Console.WriteLine(MystrPad + di.Name);

foreach (DirectoryInfo MydiChild in di.GetDirectories())
ShowDirectory(MydiChild, intLevel+1);
}
catch {}
finally{}
}

public static void Main()
{
DirectoryInfo MyDirectoryInfo = new DirectoryInfo("c:\\");
ShowDirectory(MyDirectoryInfo, 0);

}

}




Code Explanation

1. create a DirectoryInfo object
2. pass it to the recursive printing routine
3. print out the directory name, after 2*intLevel spaces
4. get its children and recursively call this routine
with one more level of indenting


By
Nathan



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Directory Tree view  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Copy and Past directories
Previous Resource: Watch your folder
Return to Discussion Resource Index
Post New Resource
Category: File Operations


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use