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 » C# Syntax »

deleting empty folder


Posted Date: 02 Oct 2009    Resource Type: Code Snippets    Category: C# Syntax
Author: manibabu.gMember Level: Gold    
Rating: 1 out of 5Points: 5




using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace DeleteEmptySubFolder
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Path");
string Path=Console.ReadLine();

DirectoryInfo di=new DirectoryInfo(Path);
DeleteEmptySubFolder1(di);

}

public static void DeleteEmptySubFolder1(DirectoryInfo di)
{


if ((di.Exists))
{
foreach (FileInfo fi in di.GetFiles())
{
//if ((fi.Exists& fi.Name.Length > 0))
//{
// if ((fi.Name.Split("_"[0]).Length <= 1))
// {
// fi.Delete();
// }

//}
}


foreach (DirectoryInfo sdi in di.GetDirectories())
{
if ((sdi.GetDirectories().Length == 0 & sdi.GetFiles().Length == 0))
{
sdi.Delete();
}
else
{
DeleteEmptySubFolder1(sdi);
}
}
if ((di.GetDirectories().Length == 0 & di.GetFiles().Length == 0))
{
di.Delete();

}
}
}

}
}



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.
Delete folder  .  C #  .  

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: DragDrop events in Windows Controls.
Previous Resource: Prevent Closing Window Forms In C#.Net
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use