Nat*_*mso 4 vb.net file-io delete-directory
是否可以删除文件夹中的所有子文件夹(包含内容)和文件?
例如:
有一个根文件夹(备份).此根文件夹包含3个子文件夹(包含内容)和3个文本文件.如何删除备份文件夹的整个内容(3个子文件夹和3个文件)而不删除根文件夹(备份)本身?
该目录类有一个删除它接受递归强制通过该文件夹的删除操作的参数方法
' Loop over the subdirectories and remove them with their contents
For Each d in Directory.GetDirectories("C:\Backup")
Directory.Delete(d, true)
Next
' Finish removing also the files in the root folder
For Each f In Directory.GetFiles("c:\backup")
File.Delete(f)
Next
Run Code Online (Sandbox Code Playgroud)
来自MSDN Directory.Delete
删除指定的目录,如果指示,则删除目录中的所有子目录和文件.