Hi all, I want to delete all .rar extension file from all directory with particular drive. Say i have "D:\Test" under this i have created many .rar files or .zip files. Once the program run only all .rar file should be deleted and other extension files should remain same and it should display that how many no of rar files have been deleted. I can create n of files in n detpht of subdirectory but while program run all .rar files should be deleted. For this i have written a program, and i have created many files in that particular drive, but when i am running the application saying that there is no files i mean its always checking the else condition. Here is my code pls somebody modify it.
static void Main(string[] args)
{
DirectoryInfo dirMain = new DirectoryInfo("D:\\Test");
if (dirMain != null)
{
FileInfo[] dirRar = dirMain.GetFiles("*.rar", SearchOption.AllDirectories);
if (dirRar != null && dirRar.Length > 0)
{
for (int i = 0; i < dirRar.Length; i++)
{
Console.WriteLine(dirRar[i].FullName);
dirRar[i].Delete();
}
Console.WriteLine("Total no of files deleted" + dirRar.Length.ToString());
}
else
{
Console.WriteLine("There is no file");
}
}
Console.ReadKey();
}