删除vb.net中的子文件夹和文件 [英] Delete subfolders and files in vb.net
问题描述
例如:
- 备用
- 11月
- pic1.jpg
- pic2.jpg
- pic1.jpg
- 十二月
- 一月
- pic3.jpg
- example1.txt
- example2。 txt
- example3.txt
- 11月
有一个根文件夹(备份)。此根文件夹包含3个子文件夹(含内容)和3个文本文件。如何删除备份文件夹的全部内容(3个子文件夹和3个文件),而不删除根文件夹(备份)本身? 解决方案
目录类有一个删除方法,接受一个参数,在传递的文件夹上递归地强制删除操作。
'Loop over子目录并将其内容删除
对于Directory.GetDirectories(C:\ Backup)中的每个d
Directory.Delete(d,true)
下一个
'完成删除根文件夹中的文件
For Each f在Directory.GetFiles(c:\backup)
File.Delete(f)
Next
FROM MSDN Directory.Delete
删除指定的目录,如果指定了任何子目录
和文件目录。
Is it possible to delete all the subfolders (with content) and files within a folder?
For example:
- Backup
- November
- pic1.jpg
- pic2.jpg
- December
- January
- pic3.jpg
- example1.txt
- example2.txt
- example3.txt
- November
There is a root folder (Backup). This root folder contains 3 subfolders (with content) and 3 text files. How can I delete the whole content (3 subfolders and 3 files) of the Backup folder without deleting the root folder (Backup) itself?
The Directory class has a Delete method that accepts a parameter that forces the deleting operation recursively on the folder passed
' 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
FROM MSDN Directory.Delete
Deletes the specified directory and, if indicated, any subdirectories and files in the directory.
这篇关于删除vb.net中的子文件夹和文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!