Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports System.IO
Partial Public Class Form1
Inherits Form
Private maxbytes As Integer = 0
Private copied As Integer = 0
Private total As Integer = 0
Private otkuda As String = "c:\My downloads\"
Private kuda As String = "c:\Install\" + Date.Today + "\My downloads\"
Public Sub New()
InitializeComponent()
End Sub
Public Sub Copy1(sourceDirectory As String, targetDirectory As String)
Dim diSource As New DirectoryInfo(sourceDirectory)
Dim diTarget As New DirectoryInfo(targetDirectory)
'Получает размер всех файлов, присутствующих в исходной папке.
GetSize(diSource, diTarget)
maxbytes = maxbytes \ 1024
ProgressBar1.Maximum = maxbytes
CopyAll(diSource, diTarget)
End Sub
Public Sub CopyAll(source As DirectoryInfo, target As DirectoryInfo)
If Directory.Exists(target.FullName) = False Then
Directory.CreateDirectory(target.FullName)
End If
For Each fi As FileInfo In source.GetFiles()
fi.CopyTo(Path.Combine(target.ToString(), fi.Name), True)
total += CInt(fi.Length)
copied += CInt(fi.Length)
copied /= 1024
ProgressBar1.[Step] = copied
ProgressBar1.PerformStep()
label1.Text = (total \ 1048576).ToString() & "MB of " & (maxbytes \ 1024).ToString() & "MB copied"
label1.Refresh()
Next
For Each diSourceSubDir As DirectoryInfo In source.GetDirectories()
Dim nextTargetSubDir As DirectoryInfo = target.CreateSubdirectory(diSourceSubDir.Name)
CopyAll(diSourceSubDir, nextTargetSubDir)
Next
End Sub
Public Sub GetSize(source As DirectoryInfo, target As DirectoryInfo)
If Directory.Exists(target.FullName) = False Then
Directory.CreateDirectory(target.FullName)
End If
For Each fi As FileInfo In source.GetFiles()
'Размер файла
maxbytes += CInt(fi.Length)
Next
For Each diSourceSubDir As DirectoryInfo In source.GetDirectories()
Dim nextTargetSubDir As DirectoryInfo = target.CreateSubdirectory(diSourceSubDir.Name)
GetSize(diSourceSubDir, nextTargetSubDir)
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Copy1(otkuda, kuda)
MessageBox.Show("Готово")
End Sub
End Class