VB.Net 删除文件夹中的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37010591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.Net Delete all files in folder
提问by Stefan ?or?evi?
I am trying to delete all files from single folder in VB.Net but to keep that folder.
我试图从 VB.Net 中的单个文件夹中删除所有文件,但要保留该文件夹。
As far as i know, i can delete files by this way:
据我所知,我可以通过这种方式删除文件:
Dim heart17 As System.IO.FileInfo = New IO.FileInfo("path")
heart17.Delete()
And it works, but i need to empty a whole folder.
它有效,但我需要清空整个文件夹。
The folder path is
文件夹路径是
C:\Users\username\Desktop\Games
.
C:\Users\username\Desktop\Games
.
I've read this question, but it doesn't work for me (it has some errors or i did something wrong).
我读过这个问题,但它对我不起作用(它有一些错误或者我做错了什么)。
回答by sujith karivelil
This will help you to delete all filesin the specified directory you can specify the search pattern to delete files that satisfies the pattern; some possible search patterns are:
这将帮助您删除指定目录中的所有文件您可以指定搜索模式删除满足模式的文件;一些可能的搜索模式是:
"*.jpg"
- selects alljpg
files.
"*.txt"
- selects all text files.
"*123.txt"
selects all text files whose name ends with123
"*.jpg"
- 选择所有jpg
文件。
"*.txt"
- 选择所有文本文件。
"*123.txt"
选择名称以123
Dim directoryName As String = "your path here"
For Each deleteFile In Directory.GetFiles(directoryName ,"*.*",SearchOption.TopDirectoryOnly)
File.Delete(deleteFile)
Next
回答by Stefan Meyer
What about
关于什么
FileSystem.Kill ("c:\path\*.*")
FileSystem.Kill ("c:\path\*.jpg")
etc.?
等等。?
回答by Doug Null
IO.Directory.Delete(
IO.Directory.Delete(
"true" means blow everything away: all sub-dirs. and files
“真”意味着吹走一切:所有子目录。和文件