How to check a folder before deleting it using windows application ?
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pramod Kumar NandagiriRank #6,963 · 252 reputationPosted Feb 21, 2012, 1:17 AM EST
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...
Anjana Prasanth6 reputationPosted Feb 21, 2012, 1:38 AM EST
Pramod Kumar NandagiriRank #6,963 · 252 reputationPosted Feb 21, 2012, 2:30 AM EST
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 Prasanth6 reputationPosted Feb 22, 2012, 7:25 PM EST