C# – Delete all files in a directory
Use Directory.EnumerateFiles() to get the file paths in a directory. Then loop over the file paths and delete each file. Here’s an example: This deletes the root directory’s files without deleting the directory itself. I’ll show more examples. Delete all files with a specific extension Use Directory.EnumerateFiles’ searchPattern pattern to search for files with a … Read more