简体   繁体   English

如何在VB.net中复制/移动/删除多个文件和文件夹?

[英]How to Copy/Move/Delete multiple files and folders in VB.net?

I would like to Copy/Move/Delete multiple files and folders in VB.net using the Microsoft.visualBasic.FileIO.FileSystem methods, with the UIOption.ShowAllDialogs parameter so that I can see the built-in progress window.Currently what I do is just loop through the list of files and folders and call the appropriate method for each item(say filesystem.deletefile), but this would open up separate progress dialogs for each item being deleted, and more annoyingly, it would ask you to confirm the deletion (the yes/no dialog) for each file being deleted.Is there any way to resolve this issue? 我想使用Microsoft.visualBasic.FileIO.FileSystem方法和UIOption.ShowAllDialogs参数在VB.net中复制/移动/删除多个文件和文件夹,以便可以看到内置的进度窗口。只是循环浏览文件和文件夹列表并为每个项目调用适当的方法(例如filesystem.deletefile),但这将为要删除的每个项目打开单独的进度对话框,更令人讨厌的是,它会要求您确认删除每个文件的删除(是/否对话框)。有什么方法可以解决此问题? Thanks for any help in advance. 感谢您的任何帮助。

Edit: Here is my current code: 编辑:这是我当前的代码:

Dim FilesToBeDeleted As new list(of String)'List of files to be deleted

Private Sub DeleteButton_Clicked() Handles DeleteButton.Click 

For each X in FilesToBeDeleted
   My.Computer.FileSystem.DeleteFile(X,FileIO.UIOption.AllDialogs,        
   FileIO.RecycleOption.SendToRecycleBin)
Next X

End Sub

One thing you can do is remove the dialog options. 您可以做的一件事是删除对话框选项。 This means that nothing will come up, and all the files will be deleted without letting the user know. 这意味着什么都不会出现,并且所有文件都将被删除而不会通知用户。 If you wanted to let them know, you could make your own notification form even with a progress bar. 如果您想让他们知道,即使有进度栏,也可以制作自己的通知表单。

Here is what that code would look like: 该代码如下所示:

    For Each X In FilesToBeDeleted
        My.Computer.FileSystem.DeleteFile(X)
    Next X
For Each X In FilesToBeDeleted
    System.IO.File.Delete(X)
Next X

You'll have to add a progress bar using BackgroundWorker to show the progress of your action. 您必须使用BackgroundWorker添加进度条以显示操作的进度。 Or check this link, it migt be helpful in simulating default windows dialog box for these actions: Download Dialog box with progress bar like windows 或检查此链接,对于模拟这些操作的默认Windows对话框可能会有所帮助: 具有进度条(如Windows)的“下载”对话框

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM