vb.net复制文件夹和进度条的内容

时间:2014-10-02 17:15:49

标签: vb.net

我正在尝试创建一个备份程序来复制目录中的文件,并在整个复制过程中运行进度条。我使用以下代码。看起来代码只复制实际文件,而不是目录中的所有内容。如何使下面的代码复制目录中的所有内容?

 Private Sub backupL01()
       Dim xNewLocataion = My.Settings.dest
        If Not Directory.Exists(xNewLocataion) Then
            Directory.CreateDirectory(xNewLocataion)
        End If
        Dim xFilesCount = Directory.GetFiles(My.Settings.source).Length
        Dim xFilesTransferred As Integer = 0

        For Each xFiles In Directory.GetFiles(My.Settings.source)

            File.Copy(xFiles, xNewLocataion & "\" & Path.GetFileName(xFiles), True)
            xFilesTransferred += 1

            ProgressBar1.Value = xFilesTransferred * 100 / xFilesCount
            ProgressBar1.Update()

            'MsgBox("Backup has been completed.", , "Backup")
            'ProgressBar1.Value = 0
        Next
    End Sub

1 个答案:

答案 0 :(得分:1)

我只是要使用它,对于我使用它的内容很好:

Dim xNewLocataion = My.Settings.dest
        If Not Directory.Exists(xNewLocataion) Then
            Directory.CreateDirectory(xNewLocataion)
        End If
        My.Computer.FileSystem.CopyDirectory(My.Settings.source, My.Settings.dest, showUI:=FileIO.UIOption.AllDialogs)