RAKESH HOLKAR
RAKESH HOLKAR

Reputation: 2197

How can we delete multiple file in C#?

File.Delete(path);

I am using function above. I have multiple file. How can i delete multiple file without calling File.Delete() function multiple time?

Upvotes: 1

Views: 631

Answers (3)

Richard Szalay
Richard Szalay

Reputation: 84734

Outside of deleting the entire directory, you have no choice but to call File.Delete multiple times. As per the documentation, the path argument is:

The name of the file to be deleted. Wildcard characters are not supported

Upvotes: 1

James
James

Reputation: 82096

There are no solutions that will allow you to delete multiple files using File.Delete with a single call. If your worried about performance you could put your code into a background thread.

Upvotes: 1

Axxelsian
Axxelsian

Reputation: 807

The files that you have multiples of must have different extensions, and in the path you have to specify which one you would like to delete, so if the files that are constantly in multiples are the same few extensions(.exe etc) then run a loop that gets the filename and adds on each extension to delete them.

Upvotes: 0

Related Questions