我正在尝试从 Application Data 文件夹中删除 3 个文件(file1.sol file2.sol file3.sol)。我的代码字一个文件就可以了,但是我怎样才能让它删除三个文件呢?
这是我的代码:
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