How to check a folder before deleting it using windows application ?
How to check a folder before deleting it using windows application ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Anjana PrasanthPosted Feb 23, 2012, 12:25 AM
Pramod Kumar NandagiriPosted Feb 21, 2012, 7:30 AM
Do you want to check whether folder has any files or sub directories then use
if(Directory.Exists("E:\\newfolder"))
{
try
{
Directory.Delete("E:\\newfolder");
// the above method deletes the newfolder only if it is empty
}
catch
{
MessageBox.Show("Permission Denied")
}
}
you should have to explain what do you want to check in folder clearly...
Anjana PrasanthPosted Feb 21, 2012, 6:38 AM
Pramod Kumar NandagiriPosted Feb 21, 2012, 6:17 AM
button1_click
{
if(Directory.Exists("E:\\newfolder"))
{
Directory.Delete("E:\\newfolder",true);
}
}
... Please do not forget to mark the thread as "Accepted Answer" if if helps you...