0

我正在尝试从 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
4

1 回答 1

0

中的第一行GetAllAccesibleFiles是搜索名称为“file1.sol”的文件,这意味着它只会检索该文件。尝试“file*.sol”,这意味着它以“file”开头并以“.sol”结尾。那应该行得通。如果你只想删除file1、2和3,而不是file4,那么你可以运行for循环3次,检查“file1”是否存在,删除它,检查“file2”是否存在,等等。

于 2014-04-05T01:05:53.073 回答