如何删除子目录 [英] How to delete subdirectories
本文介绍了如何删除子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说a有一些路径:
C:\Temp\TestFolder1\TestFolder2
Lets say a have some path: C:\Temp\TestFolder1\TestFolder2
一些模板:
C:\Temp
所以我想编写一个函数,该函数将按模板删除所有子目录
So I want to write function that will delete all subdirectories by template
void DeleteSubdirectories(string tlt, string path) {}
如果我使用给定参数调用此函数
If I call this function with given parameters
DeleteSubdirectories("C:\Temp", "C:\Temp\TestFolder1\TestFolder2");
必须从 C中删除 TestFolder1\TestFolder2 子目录:\Temp
It must delete TestFolder1\TestFolder2 subdirectories from 'C:\Temp
编写此函数的最佳方法是什么?
What is the best way to write this function?
推荐答案
如果您也想使用 C:\Temp,请使用以下方法:
If you desire to delecte "C:\Temp" too, use this:
System.IO.Directory.Delete(@"C:\Temp", true);
如果只想删除子目录,请使用以下命令:
If you just want to delete the sub directories use this:
foreach (var subDir in new DirectoryInfo(@"C:\Temp").GetDirectories()) {
subDir.Delete(true);
}
这篇关于如何删除子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文