我正在尝试删除3个文件(file1.sol file2.sol file3.sol) 从Application Data文件夹中。我的代码字很好用一个文件,但我怎么能删除这三个文件?
这是我的代码:
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Dim path As String = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Dim fileList As New List(Of String)
GetAllAccessibleFiles(path, fileList)
Application.DoEvents()
Dim files As String() = fileList.ToArray
For Each s As String In fileList
My.Computer.FileSystem.DeleteFile(s)
Next
End Sub
Sub GetAllAccessibleFiles(ByVal path As String, ByVal filelist As List(Of String))
For Each file As String In Directory.GetFiles(path, "file1.sol")
filelist.Add(file)
Next
For Each file As String In Directory.GetFiles(path, "file2.sol")
filelist.Add(file)
Next
For Each file As String In Directory.GetFiles(path, "file3.sol")
filelist.Add(file)
Next
For Each dir As String In Directory.GetDirectories(path)
Try
GetAllAccessibleFiles(dir, filelist)
Catch ex As Exception
End Try
Next
End Sub
答案 0 :(得分:0)
GetAllAccesibleFiles
中的第一行正在搜索名称为“file1.sol”的文件,这意味着它只会检索该文件。尝试“file * .sol”意味着它以“file”开头并以“.sol”结尾。这应该工作。如果你只想删除file1,2和3,例如file4,那么你可以运行for循环3次,检查是否存在“file1”,删除它,检查是否存在“file2”,依此类推。