我正在尝试创建一个程序,该程序将按特定质量(例如关键字,上次修改日期,文件类型)移动或删除文件。对于每个选项,我都有一个单选按钮,带有一个带有存档或删除选项的下拉框,一个带有关键字选项的文本框,以及一个用于文件类型和最后修改日期的下拉列表。附件是将执行这些操作的按钮的子项,以及第一个选项的操作开始。我的问题是:如何根据其规格删除或移动这些文件? (filepath变量是它将在其中工作的目录)
Private Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
Dim filepath As String
Dim keyword As String
keyword = boxKeyword.Text
filepath = txtPathBox.Text
Dim fileList1 As String() = Directory.GetFiles(filepath, keyword)
If btnOption1.Checked = True Then
If boxOption1.SelectedText = "Delete" Then
For Each file As String In fileList1
MessageBox.Show(file, "will be deleted")
System.IO.File.Delete(file)
Next
End If
End If
End Sub
答案 0 :(得分:0)
您可以使用这样的结构,并在循环中检查所需的内容,以决定是否必须移动文件...
Private Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
Dim filepath As String
filepath = txtPathBox.Text
For Each strFile As String In IO.Directory.GetFiles(filepath)
'strFile gets the full path + filename (Example: C:\Folder1\myFile.txt)
If btnOption1.Checked = True Then
'Move File?
ElseIf ... Then
'Move File?
ElseIf ... Then
'Move File?
End If
Next
End Sub