Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hello guys,

Any body please help me.
How to delete multiple files same extension, same time in a same directory without using any kind of loop.

In one directory contain as like .xml, .doc extensions file.

Thanks.

Sanwar
Posted
Updated 20-Jun-12 3:08am
v2
Comments
Mendor81 20-Jun-12 9:43am    
and why wouldn't you use a anykind of loop?
sanwar_mal_jat 20-Jun-12 9:58am    
Because remove server burden.
Mohamed Mitwalli 20-Jun-12 16:47pm    
what about recursive function or did you check solution 4 For Tim Corey may be it will work with you .
Mohamed Mitwalli 25-Jun-12 3:13am    
Check solution 3 without any loops.

There is not a direct way to do what you want. Even the file system does a loop to delete files. It just doesn't show you that it is looping. If you don't want to loop in your code, write a method that takes in the parameters and loops throught the files and deletes them behind the scenes. Then you can just call that method and not see the loop.

Here is a question similar to yours that was answered the same way:

http://forums.asp.net/t/1395992.aspx/1[^]
 
Share this answer
 
Hi
Check this

1 -
using cmd.exe Without looping
C#
private void button1_Click(object sender, EventArgs e)
{
    System.Diagnostics.Process.Start("CMD.exe","/c del e:\\test\\*.txt");
}


2-
using Recursive
C#
private void button1_Click(object sender, EventArgs e)
{
    DeleteT();
}
void DeleteT()
{
    DirectoryInfo di = new DirectoryInfo(@"D:\newww\New Folder\");
    FileInfo[] files = (di.GetFiles("*.txt")
                         .Where(p => p.Extension == ".txt")).ToArray();
    int xxx = files.ToList().Count;
    if (xxx !=0)
    {
        files.FirstOrDefault().Delete();
        DeleteT();
    }
}


Best Regards
M.Mitwalli
 
Share this answer
 
v3
Comments
Mendor81 20-Jun-12 9:59am    
That is also a loop as far as i know :P
Mohamed Mitwalli 20-Jun-12 16:45pm    
I thought he doesn't want use iteration loops so i recommend for him recursive function but as i know this task has to be with any kind of loops . :)
sanwar_mal_jat 25-Jun-12 6:24am    
Thanks for Solution ,

No1. process help full , but when it is run show command prompt for a few second, so i do not use this method .

No2. As like recursive function and a loop boot are time consuming process.
Mohamed Mitwalli 25-Jun-12 7:28am    
So both solution didn't help at the end :( i will think in another way to solve this issue
sanwar_mal_jat 25-Jun-12 8:50am    
Ya sir absolutely i am waiting it.....

Thanks
You can't. The File.Delete function does not support multiple file names, or wildcard specifications.
MSDN File.Delete[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900