How to remove files from a folder in WPF?
To delete files within a folder in WPF, you can use the Directory and File classes under the System.IO namespace. Here is an example code:
using System.IO;
// 删除文件夹下的文件
void DeleteFilesInFolder(string folderPath)
{
if (Directory.Exists(folderPath))
{
// 获取文件夹中的所有文件
string[] files = Directory.GetFiles(folderPath);
foreach (string file in files)
{
// 删除文件
File.Delete(file);
}
}
}
To use, simply pass the folder path to call the DeleteFilesInFolder method to delete all files in the folder.
Please note that this method will only delete the files within the folder, not the folder itself. If you need to delete the folder and all its contents, you can use the Directory.Delete method.