复制到新文件夹后,删除所有文件

时间:2018-09-03 15:16:50

标签: delete-file file-copying

'Start Button'执行以下操作:

  1. 检查.blf个文件的给定文件夹路径
  2. 将所有现有的.blf文件复制到目标文件夹
  3. 在文本文件i.e中显示文件夹的目录。在何处创建文件
  4. 显示要复制现有文件的目录,即进入服务器
  5. 复制后从父文件夹中删除文件

我该怎么做5 ..我哪里错了?

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Const DestinationDirectory As String = "C:\Users\nha4abt\Desktop\Move_Here"
    'Show the parent folder path
    TextBox1.Text = "C:\Users\nha4abt\Desktop\Ahmad_examaning_folder"
    ' Show the destination folder path
    TextBox2.Text = DestinationDirectory
    For Each FileName As String In directory.GetFiles("C:\Users\nha4abt\Desktop\Ahmad_examaning_folder", "*.blf")
        File.Copy(FileName, Path.Combine(DestinationDirectory, Path.GetFileName(FileName)))
        ListBox1.Items.Clear()
        ListBox1.Items.Add(FileName)
    Next FileName

    For Each FileName In As String In directory.GetFiles("C:\Users\nha4abt\Desktop\Ahmad_examaning_folder", "*.blf")
        File.Delete(Path.GetFileName(FileName))
    Next FileName
End Sub

1 个答案:

答案 0 :(得分:0)

我做到了,得到了结果。这更像是一个愚蠢的错误。

  Const DestinationDirectory As String = "C:\Users\nha4abt\Desktop\Move_Here"
    'Show the parent folder path
    Const ParentDirectory As String = "C:\Users\nha4abt\Desktop\Ahmad_examaning_folder"
    TextBox1.Text = ParentDirectory
    ' Show the destination folder path
    TextBox2.Text = DestinationDirectory
    ListBox1.Items.Clear()
    For Each FileName As String In Directory.GetFiles(ParentDirectory, "*.blf")
        File.Copy(FileName, Path.Combine(DestinationDirectory, Path.GetFileName(FileName)))
        File.Delete(FileName)
        ListBox1.Items.Add(FileName)
    Next FileName

End Sub