|
发表于 2019-10-25 19:26:01
|
显示全部楼层
河北省石家庄市
- /// <summary>
- /// 删除文件夹以及文件
- /// </summary>
- /// <param name="directoryPath"> 文件夹路径 </param>
- /// <param name="fileName"> 文件名称 </param>
- public static void DeleteDirectory(string directoryPath, string fileName)
- {
- //删除文件
- for (int i = 0; i < Directory.GetFiles(directoryPath).ToList().Count; i++)
- {
- if (Directory.GetFiles(directoryPath)[i] == fileName)
- {
- File.Delete(fileName);
- }
- }
- //删除文件夹
- for (int i = 0; i < Directory.GetDirectories(directoryPath).ToList().Count; i++)
- {
- if (Directory.GetDirectories(directoryPath)[i] == fileName)
- {
- Directory.Delete(fileName, true);
- }
- }
- }
复制代码 |
|