在Visual Basic中使用Kill移动文件

时间:2011-12-07 19:39:35

标签: vb.net

我正在制作桌面清洁工,我希望程序搜索文件扩展名并将其移动到每个以扩展名命名的新文件夹中。这就是我所拥有的。

Public Class Form2


Private Sub Form_Load()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
    Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()

    Me.FileReference.Text = MyFolderBrowser.SelectedPath
End Sub



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Me.Close()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    Label1.Text = "Cleaned."
    If CheckBox1.Checked = True Then
        On Error Resume Next
        Kill(Me.FileReference.Text("\*.txt"))
        If Not Directory.Exists(FileReference.Text) Then
            Directory.CreateDirectory(FileReference.Text)
        End If
    End If
End Sub


End Class

我想使用Kill(Me.FileReference.Text("\*.txt"))在目录中移动带有.txt扩展名的文件,名为Filereference.text的文本框包含使用MyFolderBrowser.SelectedPath提取的文本框。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

For Each foundFile As String In My.Computer.FileSystem.GetFiles( _
    My.Computer.FileSystem.SpecialDirectories.MyDocuments, _
    FileIO.SearchOption.SearchAllSubDirectories, "*.*")

    Dim foundFileInfo As New System.IO.FileInfo(foundFile)
    My.Computer.FileSystem.MoveFile(foundFile, "C:\StorageDir\" & foundFileInfo.Name)
Next