如何从vb.net项目中彻底删除所有子文件夹及其文件?
- 内容介绍
- 文章标签
- 相关推荐
本文共计307个文字,预计阅读时间需要2分钟。
可以删除文件夹中的所有子文件夹(包含内容)和文件吗?例如:备份 + 十一月 pic1.jpg pic2.jpg十二月 + 一月 pic3.jpg example1.txt example2.txt example3.txt有一个根文件夹(备份)。此根文件夹包含3个子文件夹。“
是否可以删除文件夹中的所有子文件夹(包含内容)和文件?例如:
>备份
>十一月
> pic1.jpg
> pic2.jpg
>十二月
>一月
> pic3.jpg
> example1.txt
> example2.txt
> example3.txt
有一个根文件夹(备份).此根文件夹包含3个子文件夹(包含内容)和3个文本文件.如何删除备份文件夹的整个内容(3个子文件夹和3个文件)而不删除根文件夹(备份)本身?
Directory类有一个Delete方法,该方法接受一个参数,该参数以递归方式强制对传递的文件夹执行删除操作' 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
来自MSDN Directory.Delete
Deletes the specified directory and, if indicated, any subdirectories and files in the directory.
本文共计307个文字,预计阅读时间需要2分钟。
可以删除文件夹中的所有子文件夹(包含内容)和文件吗?例如:备份 + 十一月 pic1.jpg pic2.jpg十二月 + 一月 pic3.jpg example1.txt example2.txt example3.txt有一个根文件夹(备份)。此根文件夹包含3个子文件夹。“
是否可以删除文件夹中的所有子文件夹(包含内容)和文件?例如:
>备份
>十一月
> pic1.jpg
> pic2.jpg
>十二月
>一月
> pic3.jpg
> example1.txt
> example2.txt
> example3.txt
有一个根文件夹(备份).此根文件夹包含3个子文件夹(包含内容)和3个文本文件.如何删除备份文件夹的整个内容(3个子文件夹和3个文件)而不删除根文件夹(备份)本身?
Directory类有一个Delete方法,该方法接受一个参数,该参数以递归方式强制对传递的文件夹执行删除操作' 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
来自MSDN Directory.Delete
Deletes the specified directory and, if indicated, any subdirectories and files in the directory.

