Check folder and Delete All Files from Existing Folder in C#
Dynamically check the Particular name Folder exist or not, it not exits create folder dynamically.
if (!Directory.Exists(FolderName))
{
Directory.CreateDirectory(FolderName);
}
if (Directory.Exists(FolderName))
{
string[] filePaths = Directory.GetFiles(FolderName);
foreach (string filePath in filePaths)
File.Delete(filePath);
//Directory.Delete(FolderName);
}
if (!Directory.Exists(FolderName))
{
Directory.CreateDirectory(FolderName);
}
if (Directory.Exists(FolderName))
{
string[] filePaths = Directory.GetFiles(FolderName);
foreach (string filePath in filePaths)
File.Delete(filePath);
//Directory.Delete(FolderName);
}
Comments
Post a Comment