Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all files from a specific folder? [closed]

Tags:

c#

.net

I save files in a specific folder at run time. After some time, I want to delete them programmatically. How do I delete all files from a specific folder?

like image 235
Michael Avatar asked Sep 06 '12 09:09

Michael


People also ask

How do I delete files from a specific folder?

Open My Computer or Windows Explorer. Locate and select the file or folder you want to delete, click File in the top menu bar, and select Delete. If the File menu is not visible in My Computer or Windows Explorer, press the Alt key to make the menu bar visible, including the file menu.

How do you delete a folder that says it is open in another program?

Try Ctrl + Shift + Esc > "programs", then right click the one you want to deactivate and choose deactivate. Then delete it again!


1 Answers

string[] filePaths = Directory.GetFiles(@"c:\MyDir\"); foreach (string filePath in filePaths) File.Delete(filePath); 

Or in a single line:

Array.ForEach(Directory.GetFiles(@"c:\MyDir\"), File.Delete); 
like image 160
CloudyMarble Avatar answered Oct 05 '22 19:10

CloudyMarble