如何使用vb.net制作类似Windows ntbackup的程序? [英] How to make a program like windows ntbackup with vb.net?

查看:73
本文介绍了如何使用vb.net制作类似Windows ntbackup的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我想制作一个具有3个功能的程序:

①,打开Windows Explorer等硬盘文件,左侧是文件夹列表,其中包括网上邻居"文件,此列表在树状视图中,每个节点均带有复选框"供选择,并带有相关图标. br/>
②,如果选择了左文件夹,则右列表视图将显示其中包含的文件,右列表视图的节点还包括复选框"以供选择,并带有相关图标.

③,我选择要备份的文件:我要使用进度条复制文件,其中显示复制速度,时间,已复制和未复制的数据大小(有时文件很大...)


只是复制文件,如果您能告诉我如何将其备份到一个文件中并且还可以扩展它,那就更好了.

请提供帮助,在此先谢谢您.

Hi,everyone.

I want make a program with 3 functions:

①、open harddisk files like windows explorer,the left is file folder list include "My Network Places" files, this list in a treeview, each node with a "check box" for select, and with it''s relevant icon.

②、if left file folder was selected, the right listview show files which were contained in it, the right listview''s node also include "check box" for select, and with it''s relevant icon.

③、I select files which I want to backup: I want to copy file with progressbar which display copy speed,time,copied and uncopy data size (some times file is very big...)


Just copy files, if you can tell me how to backup it in one file and also can expand it,is better.

Please help, thanks in advance.

推荐答案

难道不是很容易找出NTBackup的问题所在,并解决该问题,而不用花费接下来的6个月.写另一个??
Wouldn''t it be easier to find out what the problem with NTBackup is and fix that instead of spending the next 6 months writing another one??


导入System.IO
公共课程表格1
继承System.Windows.Forms.Form

#Region"Windows常规设计器生成的代码"

Public Sub New()
MyBase.New()

''该调用是Windows常规设计器所必需的. InitializeComponent()

''在InitializeComponent()调用之后添加任何初始化

结束子

''压缩重新配置以清理组件列表.
受保护的重载将覆盖Sub Dispose(按Boolean方式进行ByVal处理)
如果处理然后
如果没有(组件什么都没有),那么
components.Dispose()
如果结束
如果结束
MyBase.Dispose(处置)
结束子

''Windows常规设计器所必需的
私有组件作为System.ComponentModel.IContainer

''注意:以下过程是Windows集成设计器所必需的
''可以使用Windows常规设计器修改此过程.
''不要使用代码编辑器修改它.
朋友WithEvents Timer1 As System.Windows.Forms.Timer
朋友WithEvents Label1作为System.Windows.Forms.Label
朋友WithEvents ProgressBar1作为System.Windows.Forms.ProgressBar
朋友WithEvents Label9作为System.Windows.Forms.Label
朋友WithEvents Label8作为System.Windows.Forms.Label
朋友WithEvents Label7作为System.Windows.Forms.Label
朋友WithEvents Label6作为System.Windows.Forms.Label
朋友WithEvents Label5作为System.Windows.Forms.Label
朋友WithEvents Label4作为System.Windows.Forms.Label
朋友WithEvents Label3作为System.Windows.Forms.Label
朋友WithEvents Label2作为System.Windows.Forms.Label
朋友WithEvents fTime作为System.Windows.Forms.GroupBox
Friend WithEvents LProcessed作为System.Windows.Forms.Label
朋友WithEvents LTime保留为System.Windows.Forms.Label
朋友WithEvents LTimeElapsed作为System.Windows.Forms.Label
朋友WithEvents LfileBytesTotal作为System.Windows.Forms.Label
朋友WithEvents LProcessedBytes作为System.Windows.Forms.Label
朋友WithEvents LfileTotal作为System.Windows.Forms.Label
朋友WithEvents GroupBox1作为System.Windows.Forms.GroupBox
朋友WithEvents Button1作为System.Windows.Forms.Button
朋友WithEvents Button2作为System.Windows.Forms.Button
朋友WithEvents LfileProcessed作为System.Windows.Forms.Label
< system.diagnostics.debuggerstepthrough()>私有子InitializeComponent()
Me.components =新的System.ComponentModel.Container
Me.Timer1 =新的System.Windows.Forms.Timer(Me.components)
Me.fTime =新的System.Windows.Forms.GroupBox
Me.LfileBytesTotal =新的System.Windows.Forms.Label
Me.LProcessedBytes =新的System.Windows.Forms.Label
Me.LfileTotal =新的System.Windows.Forms.Label
Me.LfileProcessed =新的System.Windows.Forms.Label
Me.LProcessed =新的System.Windows.Forms.Label
Me.LTimeRemaining =新的System.Windows.Forms.Label
Me.LTimeElapsed =新的System.Windows.Forms.Label
Me.Label9 =新的System.Windows.Forms.Label
Me.Label8 =新的System.Windows.Forms.Label
Me.Label7 =新的System.Windows.Forms.Label
Me.Label6 =新的System.Windows.Forms.Label
Me.Label5 =新的System.Windows.Forms.Label
Me.Label4 =新的System.Windows.Forms.Label
Me.Label3 =新的System.Windows.Forms.Label
Me.Label2 =新的System.Windows.Forms.Label
Me.Label1 =新的System.Windows.Forms.Label
Me.ProgressBar1 =新的System.Windows.Forms.ProgressBar
Me.GroupBox1 =新的System.Windows.Forms.GroupBox
Me.Button2 =新的System.Windows.Forms.Button
Me.Button1 =新的System.Windows.Forms.Button
Me.fTime.SuspendLayout()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
''
''Timer1
''
Me.Timer1.Enabled = True
''
''fTime
''
Me.fTime.Controls.Add(Me.LfileBytesTotal)
Me.fTime.Controls.Add(Me.LProcessedBytes)
Me.fTime.Controls.Add(Me.LfileTotal)
Me.fTime.Controls.Add(Me.LfileProcessed)
Me.fTime.Controls.Add(Me.LProcessed)
Me.fTime.Controls.Add(Me.LTimeRemaining)
Me.fTime.Controls.Add(Me.LTimeElapsed)
Me.fTime.Controls.Add(Me.Label9)
Me.fTime.Controls.Add(Me.Label8)
Me.fTime.Controls.Add(Me.Label7)
Me.fTime.Controls.Add(Me.Label6)
Me.fTime.Controls.Add(Me.Label5)
Me.fTime.Controls.Add(Me.Label4)
Me.fTime.Controls.Add(Me.Label3)
Me.fTime.Controls.Add(Me.Label2)
Me.fTime.Controls.Add(Me.Label1)
Me.fTime.Controls.Add(Me.ProgressBar1)
Me.fTime.Location =新的System.Drawing.Point(8,8)
Me.fTime.Name ="fTime"
Me.fTime.Size =新的System.Drawing.Size(560,336)
Me.fTime.TabIndex = 19
Me.fTime.TabStop = False
''
''LfileBytesTotal
''
Me.LfileBytesTotal.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LfileBytesTotal.Location =新System.Drawing.Point(297,281)
Me.LfileBytesTotal.Name ="LfileBytesTotal"
Me.LfileBytesTotal.Size =新的System.Drawing.Size(187,24)
Me.LfileBytesTotal.TabIndex = 40
Me.LfileBytesTotal.Text ="LfileBytesTotal"
''
''LProcessedBytes
''
Me.LProcessedBytes.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LProcessedBytes.Location =新System.Drawing.Point(94,281)
Me.LProcessedBytes.Name ="LProcessedBytes"
Me.LProcessedBytes.Size =新的System.Drawing.Size(187,24)
Me.LProcessedBytes.TabIndex = 39
Me.LProcessedBytes.Text ="LProcessedBytes"
''
''LfileTotal
''
Me.LfileTotal.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LfileTotal.Location =新System.Drawing.Point(297,232)
Me.LfileTotal.Name ="LfileTotal"
Me.LfileTotal.Size =新的System.Drawing.Size(187,24)
Me.LfileTotal.TabIndex = 38
Me.LfileTotal.Text ="LfileTotal"
''
''LfileProcessed
''
Me.LfileProcessed.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LfileProcessed.Location =新System.Drawing.Point(94,232)
Me.LfileProcessed.Name ="LfileProcessed"
Me.LfileProcessed.Size =新的System.Drawing.Size(187,24)
Me.LfileProcessed.TabIndex = 37
Me.LfileProcessed.Text ="LfileProcessed"
''
''LProcessed
''
Me.LProcessed.BackColor = System.Drawing.Color.Transparent
Me.LProcessed.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LProcessed.Location =新System.Drawing.Point(94,160)
Me.LProcessed.Name ="LProcessed"
Me.LProcessed.Size =新System.Drawing.Size(390,24)
Me.LProcessed.TabIndex = 36
Me.LProcessed.Text ="LProcessed"
''
''LTimeRemaining
''
Me.LTimeRemaining.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LTimeRemaining.Location =新System.Drawing.Point(297,113)
Me.LTimeRemaining.Name ="LTimeRemaining"
Me.LTimeRemaining.Size =新的System.Drawing.Size(187,24)
Me.LTimeRemaining.TabIndex = 35
Me.LTimeRemaining.Text ="LTimeRemaining"
''
''LTimeElapsed
''
Me.LTimeElapsed.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LTimeElapsed.Location =新System.Drawing.Point(94,113)
Me.LTimeElapsed.Name ="LTimeElapsed"
Me.LTimeElapsed.Size =新System.Drawing.Size(187,24)
Me.LTimeElapsed.TabIndex = 34
Me.LTimeElapsed.Text ="LTimeElapsed"
''
''Label9
''
Me.Label9.AutoSize = True
Me.Label9.Location =新System.Drawing.Point(41,285)
Me.Label9.Name ="Label9"
Me.Label9.Size =新的System.Drawing.Size(42,16)
Me.Label9.TabIndex = 31
Me.Label9.Text =字节:"
''
''Label8
''
Me.Label8.AutoSize = True
Me.Label8.Location =新System.Drawing.Point(294,200)
Me.Label8.Name ="Label8"
Me.Label8.Size =新的System.Drawing.Size(42,16)
Me.Label8.TabIndex = 30
Me.Label8.Text =估计:"
''
''Label7
''
Me.Label7.AutoSize = True
Me.Label7.Location =新System.Drawing.Point(92,200)
Me.Label7.Name ="Label7"
Me.Label7.Size =新的System.Drawing.Size(54,16)
Me.Label7.TabIndex = 28
Me.Label7.Text =已处理:"
''
''Label6
''
Me.Label6.AutoSize = True
Me.Label6.Location =新System.Drawing.Point(25,237)
Me.Label6.Name ="Label6"
Me.Label6.Size =新的System.Drawing.Size(54,16)
Me.Label6.TabIndex = 27
Me.Label6.Text =文件数:"
''
''Label5
''
Me.Label5.AutoSize = True
Me.Label5.Location =新System.Drawing.Point(17,166)
Me.Label5.Name ="Label5"
Me.Label5.Size =新的System.Drawing.Size(66,16)
Me.Label5.TabIndex = 24
Me.Label5.Text =正在处理:"
''
''Label4
''
Me.Label4.AutoSize = True
Me.Label4.Location =新System.Drawing.Point(41,117)
Me.Label4.Name ="Label4"
Me.Label4.Size =新的System.Drawing.Size(42,16)
Me.Label4.TabIndex = 23
Me.Label4.Text =时间:"
''
''Label3
''
Me.Label3.AutoSize = True
Me.Label3.Location =新System.Drawing.Point(296,80)
Me.Label3.Name ="Label3"
Me.Label3.Size =新的System.Drawing.Size(91,16)
Me.Label3.TabIndex = 21
Me.Label3.Text =估计剩余时间:"
''
''Label2
''
Me.Label2.AutoSize = True
Me.Label2.Location =新System.Drawing.Point(91,83)
Me.Label2.Name ="Label2"
Me.Label2.Size =新的System.Drawing.Size(66,16)
Me.Label2.TabIndex = 20
Me.Label2.Text =已用时间:"
''
''Label1
''
Me.Label1.AutoSize = True
Me.Label1.Location =新System.Drawing.Point(41,41)
Me.Label1.Name ="Label1"
Me.Label1.Size =新System.Drawing.Size(42,16)
Me.Label1.TabIndex = 6
Me.Label1.Text =进度:"
''
''ProgressBar1
''
Me.ProgressBar1.Location =新System.Drawing.Point(94,36)
Me.ProgressBar1.Name ="ProgressBar1"
Me.ProgressBar1.Size =新的System.Drawing.Size(390,24)
Me.ProgressBar1.TabIndex = 5
''
''GroupBox1
''
Me.GroupBox1.Controls.Add(Me.Button2)
Me.GroupBox1.Controls.Add(Me.Button1)
Me.GroupBox1.Location =新System.Drawing.Point(8,360)
Me.GroupBox1.Name ="GroupBox1"
Me.GroupBox1.Size =新的System.Drawing.Size(560,64)
Me.GroupBox1.TabIndex = 20
Me.GroupBox1.TabStop = False
''
''Button2
''
Me.Button2.Location =新System.Drawing.Point(312,20)
Me.Button2.Name ="Button2"
Me.Button2.Size =新的System.Drawing.Size(75,32)
Me.Button2.TabIndex = 3
Me.Button2.Text =取消"
''
''Button1
''
Me.Button1.Location =新的System.Drawing.Point(144,20)
Me.Button1.Name ="Button1"
Me.Button1.Size =新的System.Drawing.Size(75,32)
Me.Button1.TabIndex = 2
Me.Button1.Text =开始"
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5,13)
Me.ClientSize =新的System.Drawing.Size(576,438)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.fTime)
Me.Name ="Form1"
Me.Text =文件复制"
Me.fTime.ResumeLayout(False)
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)

结束子

#End Region

将Dim fFinish设为Double
Dim fWriteSize As Integer''每次写入文件的字节数
Dim fCount As Integer''已经复制的文件数
Dim timeCount As Double''已经复制的时间
单身的昏暗
Dim fExit As Boolean = False
Dim fCancel As Boolean = False
Dim fcompleted As Boolean = False''判断是否复制完成
Dim firstT As New Double''起始时间
昏暗的文件大小为新的Double''文件大小
昏暗的fileizeTotal作为新的Double''文件大小

公共共享函数filelen(ByVal SourceFile作为字符串)作为Double
试试
昏暗的getfilelen作为新System.IO.FileInfo(SourceFile)
filelen = CDbl(getfilelen.Length)
异常捕获
MsgBox(ex.Message.ToString,64)
结束尝试

最终功能
私有子Button1_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理Button1.Click

如果Format(Now,"HH:mm")<> "07:00"然后
退出子
如果结束

Button1.Enabled =假

昏暗的copysource(4),TargetFilePath作为字符串
Dim i As Integer
TargetFilePath ="D:\ IT \ Data \"
copysource(0)="\\ 192.168.43.3 \ backup \ Datadb \ HuRis"
copysource(1)="\\ 192.168.43.5 \ BackUp \ TSP2011"
copysource(2)="\\ 192.168.43.3 \ backup \ Datadb \ kechr_BAK"
copysource(3)="\\ 192.168.43.3 \ backup \ Datadb \ MESC_DBF_bak"
copysource(4)="\\ 192.168.43.3 \ backup \ Datadb \ wuxitdb_bak"

试试
对于i = 0要复制source.Length-1
filesizeTotal = filesizeTotal + filelen(copysource(i))
下一个
LfileBytesTotal.Text = Format(filesizeTotal,#,###,####")&字节"
LfileTotal.Text = i
对于i = 0要复制source.Length-1
''这里写要复制的文件,复制的目标文件
firstT = Microsoft.VisualBasic.DateAndTime.Timer''开始计时
呼叫复制(copysource(i),TargetFilePath和System.IO.Path.GetFileName(copysource(i)))
LfileProcessed.Text = fCount
下一个
Me.Text ="filecopy"&Space(10)&复制完成"
fcompleted = True
Button1.Enabled = True
Button1.Text =开始"

异常捕获
MsgBox(ex.Message.ToString,64)
结束尝试

结束子

子复制(ByVal源文件为字符串,ByVal目标文件为字符串)

试试
昏暗的Readstream作为新的IO.FileStream(SourceFile,IO.FileMode.Open,IO.FileAccess.Read)
昏暗的Writestream作为新的IO.FileStream(TargetFile,IO.FileMode.Create,IO.FileAccess.Write)

Dim BReadstream作为New IO.BinaryReader(Readstream)''将基元数据类型读着作二进制值
Dim BWritestream作为新IO.BinaryWriter(Writestream)''以二进制形式将基元数据类型写入流

Dim fBlock As Integer = 1024 * 1024''每次重新读取和写入的字节数

LProcessed.Text = SourceFile''正在复制的文件

文件大小= CDbl(Readstream.Length)
ProgressBar1.Maximum = 100


Application.DoEvents()
如果退出,则退出Sub''操作未完成用户关闭了窗口
如果fCancel然后退出,请执行''用户取消了操作
如果fFinish> = filesize然后退出执行''已写入字节> =源文件
fWriteSize = fBlock''每次读取字节数
如果fWriteSize> filesize-fFinish然后''大于1个fBlock字节的按照一个单位的fBlock写入
fWriteSize = filesize-fFinish''实际读写字节数
如果结束

BWritestream.Write(BReadstream.ReadBytes(fWriteSize))''识别并写入一个fBlock字节
fFinish = fFinish + fWriteSize''逐步完成字节数

致电fJindu()
循环

fCount = fCount + 1

Readstream.Close()
Writestream.Close()

BReadstream.Close()
BWritestream.Close()
异常捕获
MsgBox(ex.Message.ToString,64)
结束尝试
结束子


子fJindu()

''显示进度
昏暗的速度,剩余时间为Single

试试
如果文件大小> 0然后
fpercent = fFinish/filesize
其他
fpercent = 0
如果结束

ProgressBar1.Value = fpercent * 100
Button1.Text = ProgressBar1.Value&%"

如果fFinish> 0然后
LProcessedBytes.Text = Format(fFinish,#,###,####")&字节"''已经复制字节
timeCount = Microsoft.VisualBasic.DateAndTime.Timer-firstT
LTimeElapsed.Text = StrTime(timeCount)''已用时间
speed = Format(fFinish/timeCount/1024/1024,#0.00")''复制速度
lefttime =(filesizeTotal-fFinish)/速度/1024/1024
LTimeRemaining.Text = StrTime(lefttime)''剩余时间
Me.Text ="filecopy"&Space(10)&速度M/s:"&speed
其他
LProcessedBytes.Text =文件大小:0"
如果结束
异常捕获
MsgBox(例如Message.ToString,MsgBoxStyle.Information)
结束尝试


结束子
私有函数StrTime(ByVal T为Double)作为字符串
昏暗的H为Double,M为Double

H = T \ 3600:T = T-H * 3600
M = T \ 60:T = T-M * 60
如果H> 0然后StrTime = H&时"
如果H> 0或M> 0然后StrTime = StrTime&M&分"
StrTime = StrTime和Format(T,#0.00")&秒"
最终功能

私有子Form1_Closing(ByVal发送者作为对象,ByVal e作为System.ComponentModel.CancelEventArgs)处理MyBase.Closing
如果fcompleted = True,那么
fExit = True
fCancel = True
e.Cancel = False''如果复制完成,直接可以退出
其他
如果fExit = False,则
Dim ss As String
ss =现有文件:"&"&Chr(13)&_
要取消复制吗?"&Chr(13)&Chr(13)&_
要立即结束复制,请中断是"&"是"&Chr(13)&"要继续复制,请中断&"否""&."

如果MsgBox(ss,MsgBoxStyle.Information + MsgBoxStyle.YesNo,复制工具")= MsgBoxResult.Yes然后
fExit = True
fCancel = True
其他
fExit = False
fCancel = False
e.Cancel = True''取消关闭
如果结束
如果结束
如果结束
结束子

私有子Button2_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理Button2.Click
Me.Close()
结束子

私有子Form1_Load(ByVal发送者作为System.Object,ByVal e作为System.EventArgs)处理MyBase.Load
LfileProcessed.Text = 0
结束子

私有子Timer1_Tick(ByVal发送者作为System.Object,ByVal e作为System.EventArgs)处理Timer1.Tick
如果Format(Now,"HH:mm")="07:00"然后
调用Button1.PerformClick()
如果结束
结束子
结束类
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()
MyBase.New()

''该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

''在 InitializeComponent() 调用之后添加任何初始化

End Sub

''窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

''Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

''注意: 以下过程是 Windows 窗体设计器所必需的
''可以使用 Windows 窗体设计器修改此过程。
''不要使用代码编辑器修改它。
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents fTime As System.Windows.Forms.GroupBox
Friend WithEvents LProcessed As System.Windows.Forms.Label
Friend WithEvents LTimeRemaining As System.Windows.Forms.Label
Friend WithEvents LTimeElapsed As System.Windows.Forms.Label
Friend WithEvents LfileBytesTotal As System.Windows.Forms.Label
Friend WithEvents LProcessedBytes As System.Windows.Forms.Label
Friend WithEvents LfileTotal As System.Windows.Forms.Label
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents LfileProcessed As System.Windows.Forms.Label
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.fTime = New System.Windows.Forms.GroupBox
Me.LfileBytesTotal = New System.Windows.Forms.Label
Me.LProcessedBytes = New System.Windows.Forms.Label
Me.LfileTotal = New System.Windows.Forms.Label
Me.LfileProcessed = New System.Windows.Forms.Label
Me.LProcessed = New System.Windows.Forms.Label
Me.LTimeRemaining = New System.Windows.Forms.Label
Me.LTimeElapsed = New System.Windows.Forms.Label
Me.Label9 = New System.Windows.Forms.Label
Me.Label8 = New System.Windows.Forms.Label
Me.Label7 = New System.Windows.Forms.Label
Me.Label6 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Button2 = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.fTime.SuspendLayout()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
''
''Timer1
''
Me.Timer1.Enabled = True
''
''fTime
''
Me.fTime.Controls.Add(Me.LfileBytesTotal)
Me.fTime.Controls.Add(Me.LProcessedBytes)
Me.fTime.Controls.Add(Me.LfileTotal)
Me.fTime.Controls.Add(Me.LfileProcessed)
Me.fTime.Controls.Add(Me.LProcessed)
Me.fTime.Controls.Add(Me.LTimeRemaining)
Me.fTime.Controls.Add(Me.LTimeElapsed)
Me.fTime.Controls.Add(Me.Label9)
Me.fTime.Controls.Add(Me.Label8)
Me.fTime.Controls.Add(Me.Label7)
Me.fTime.Controls.Add(Me.Label6)
Me.fTime.Controls.Add(Me.Label5)
Me.fTime.Controls.Add(Me.Label4)
Me.fTime.Controls.Add(Me.Label3)
Me.fTime.Controls.Add(Me.Label2)
Me.fTime.Controls.Add(Me.Label1)
Me.fTime.Controls.Add(Me.ProgressBar1)
Me.fTime.Location = New System.Drawing.Point(8, 8)
Me.fTime.Name = "fTime"
Me.fTime.Size = New System.Drawing.Size(560, 336)
Me.fTime.TabIndex = 19
Me.fTime.TabStop = False
''
''LfileBytesTotal
''
Me.LfileBytesTotal.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LfileBytesTotal.Location = New System.Drawing.Point(297, 281)
Me.LfileBytesTotal.Name = "LfileBytesTotal"
Me.LfileBytesTotal.Size = New System.Drawing.Size(187, 24)
Me.LfileBytesTotal.TabIndex = 40
Me.LfileBytesTotal.Text = "LfileBytesTotal"
''
''LProcessedBytes
''
Me.LProcessedBytes.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LProcessedBytes.Location = New System.Drawing.Point(94, 281)
Me.LProcessedBytes.Name = "LProcessedBytes"
Me.LProcessedBytes.Size = New System.Drawing.Size(187, 24)
Me.LProcessedBytes.TabIndex = 39
Me.LProcessedBytes.Text = "LProcessedBytes"
''
''LfileTotal
''
Me.LfileTotal.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LfileTotal.Location = New System.Drawing.Point(297, 232)
Me.LfileTotal.Name = "LfileTotal"
Me.LfileTotal.Size = New System.Drawing.Size(187, 24)
Me.LfileTotal.TabIndex = 38
Me.LfileTotal.Text = "LfileTotal"
''
''LfileProcessed
''
Me.LfileProcessed.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LfileProcessed.Location = New System.Drawing.Point(94, 232)
Me.LfileProcessed.Name = "LfileProcessed"
Me.LfileProcessed.Size = New System.Drawing.Size(187, 24)
Me.LfileProcessed.TabIndex = 37
Me.LfileProcessed.Text = "LfileProcessed"
''
''LProcessed
''
Me.LProcessed.BackColor = System.Drawing.Color.Transparent
Me.LProcessed.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LProcessed.Location = New System.Drawing.Point(94, 160)
Me.LProcessed.Name = "LProcessed"
Me.LProcessed.Size = New System.Drawing.Size(390, 24)
Me.LProcessed.TabIndex = 36
Me.LProcessed.Text = "LProcessed"
''
''LTimeRemaining
''
Me.LTimeRemaining.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LTimeRemaining.Location = New System.Drawing.Point(297, 113)
Me.LTimeRemaining.Name = "LTimeRemaining"
Me.LTimeRemaining.Size = New System.Drawing.Size(187, 24)
Me.LTimeRemaining.TabIndex = 35
Me.LTimeRemaining.Text = "LTimeRemaining"
''
''LTimeElapsed
''
Me.LTimeElapsed.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.LTimeElapsed.Location = New System.Drawing.Point(94, 113)
Me.LTimeElapsed.Name = "LTimeElapsed"
Me.LTimeElapsed.Size = New System.Drawing.Size(187, 24)
Me.LTimeElapsed.TabIndex = 34
Me.LTimeElapsed.Text = "LTimeElapsed"
''
''Label9
''
Me.Label9.AutoSize = True
Me.Label9.Location = New System.Drawing.Point(41, 285)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(42, 16)
Me.Label9.TabIndex = 31
Me.Label9.Text = "字节:"
''
''Label8
''
Me.Label8.AutoSize = True
Me.Label8.Location = New System.Drawing.Point(294, 200)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(42, 16)
Me.Label8.TabIndex = 30
Me.Label8.Text = "估计:"
''
''Label7
''
Me.Label7.AutoSize = True
Me.Label7.Location = New System.Drawing.Point(92, 200)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(54, 16)
Me.Label7.TabIndex = 28
Me.Label7.Text = "已处理:"
''
''Label6
''
Me.Label6.AutoSize = True
Me.Label6.Location = New System.Drawing.Point(25, 237)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(54, 16)
Me.Label6.TabIndex = 27
Me.Label6.Text = "文件数:"
''
''Label5
''
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(17, 166)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(66, 16)
Me.Label5.TabIndex = 24
Me.Label5.Text = "正在处理:"
''
''Label4
''
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(41, 117)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(42, 16)
Me.Label4.TabIndex = 23
Me.Label4.Text = "时间:"
''
''Label3
''
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(296, 80)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(91, 16)
Me.Label3.TabIndex = 21
Me.Label3.Text = "估计剩余时间:"
''
''Label2
''
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(91, 83)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(66, 16)
Me.Label2.TabIndex = 20
Me.Label2.Text = "已用时间:"
''
''Label1
''
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(41, 41)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(42, 16)
Me.Label1.TabIndex = 6
Me.Label1.Text = "进度:"
''
''ProgressBar1
''
Me.ProgressBar1.Location = New System.Drawing.Point(94, 36)
Me.ProgressBar1.Name = "ProgressBar1"
Me.ProgressBar1.Size = New System.Drawing.Size(390, 24)
Me.ProgressBar1.TabIndex = 5
''
''GroupBox1
''
Me.GroupBox1.Controls.Add(Me.Button2)
Me.GroupBox1.Controls.Add(Me.Button1)
Me.GroupBox1.Location = New System.Drawing.Point(8, 360)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(560, 64)
Me.GroupBox1.TabIndex = 20
Me.GroupBox1.TabStop = False
''
''Button2
''
Me.Button2.Location = New System.Drawing.Point(312, 20)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(75, 32)
Me.Button2.TabIndex = 3
Me.Button2.Text = "取消"
''
''Button1
''
Me.Button1.Location = New System.Drawing.Point(144, 20)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 32)
Me.Button1.TabIndex = 2
Me.Button1.Text = "开始"
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(576, 438)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.fTime)
Me.Name = "Form1"
Me.Text = "filecopy"
Me.fTime.ResumeLayout(False)
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Dim fFinish As Double
Dim fWriteSize As Integer ''每次写入文件的字节数
Dim fCount As Integer ''已经复制的文件数
Dim timeCount As Double ''已经复制的时间
Dim fpercent As Single
Dim fExit As Boolean = False
Dim fCancel As Boolean = False
Dim fcompleted As Boolean = False ''判断是否复制完成
Dim firstT As New Double ''起始时间
Dim filesize As New Double ''文件大小
Dim filesizeTotal As New Double ''文件大小

Public Shared Function filelen(ByVal SourceFile As String) As Double
Try
Dim getfilelen As New System.IO.FileInfo(SourceFile)
filelen = CDbl(getfilelen.Length)
Catch ex As Exception
MsgBox(ex.Message.ToString, 64)
End Try

End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If Format(Now, "HH:mm") <> "07:00" Then
Exit Sub
End If

Button1.Enabled = False

Dim copysource(4), TargetFilePath As String
Dim i As Integer
TargetFilePath = "D:\IT\Data\"
copysource(0) = "\\192.168.43.3\backup\Datadb\HuRis"
copysource(1) = "\\192.168.43.5\BackUp\TSP2011"
copysource(2) = "\\192.168.43.3\backup\Datadb\kechr_BAK"
copysource(3) = "\\192.168.43.3\backup\Datadb\MESC_DBF_bak"
copysource(4) = "\\192.168.43.3\backup\Datadb\wuxitdb_bak"

Try
For i = 0 To copysource.Length - 1
filesizeTotal = filesizeTotal + filelen(copysource(i))
Next
LfileBytesTotal.Text = Format(filesizeTotal, "#,###,####") & " 字节"
LfileTotal.Text = i
For i = 0 To copysource.Length - 1
''这里写要复制的文件,复制的目标文件
firstT = Microsoft.VisualBasic.DateAndTime.Timer ''开始计时
Call copying(copysource(i), TargetFilePath & System.IO.Path.GetFileName(copysource(i)))
LfileProcessed.Text = fCount
Next
Me.Text = "filecopy" & Space(10) & "复制完成"
fcompleted = True
Button1.Enabled = True
Button1.Text = "开始"

Catch ex As Exception
MsgBox(ex.Message.ToString, 64)
End Try

End Sub

Sub copying(ByVal SourceFile As String, ByVal TargetFile As String)

Try
Dim Readstream As New IO.FileStream(SourceFile, IO.FileMode.Open, IO.FileAccess.Read)
Dim Writestream As New IO.FileStream(TargetFile, IO.FileMode.Create, IO.FileAccess.Write)

Dim BReadstream As New IO.BinaryReader(Readstream) ''将基元数据类型读着作二进制值
Dim BWritestream As New IO.BinaryWriter(Writestream) ''以二进制形式将基元数据类型写入流

Dim fBlock As Integer = 1024 * 1024 ''每次读取和写入的字节数

LProcessed.Text = SourceFile ''正在复制的文件

filesize = CDbl(Readstream.Length)
ProgressBar1.Maximum = 100

Do
Application.DoEvents()
If fExit Then Exit Sub ''操作未完成用户关闭了窗口
If fCancel Then Exit Do ''用户取消了操作
If fFinish >= filesize Then Exit Do ''已写入字节>=源文件
fWriteSize = fBlock ''每次读写字节数
If fWriteSize > filesize - fFinish Then ''大于1个fBlock字节的按照一个单位的fBlock写入
fWriteSize = filesize - fFinish ''实际读写字节数
End If

BWritestream.Write(BReadstream.ReadBytes(fWriteSize)) ''读出并写入一个fBlock字节
fFinish = fFinish + fWriteSize ''累计完成字节数

Call fJindu()
Loop

fCount = fCount + 1

Readstream.Close()
Writestream.Close()

BReadstream.Close()
BWritestream.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString, 64)
End Try
End Sub


Sub fJindu()

''显示进度
Dim speed, lefttime As Single

Try
If filesize > 0 Then
fpercent = fFinish / filesize
Else
fpercent = 0
End If

ProgressBar1.Value = fpercent * 100
Button1.Text = ProgressBar1.Value & "%"

If fFinish > 0 Then
LProcessedBytes.Text = Format(fFinish, "#,###,####") & " 字节" ''已经复制字节
timeCount = Microsoft.VisualBasic.DateAndTime.Timer - firstT
LTimeElapsed.Text = StrTime(timeCount) ''已用时间
speed = Format(fFinish / timeCount / 1024 / 1024, "#0.00") ''复制速度
lefttime = (filesizeTotal - fFinish) / speed / 1024 / 1024
LTimeRemaining.Text = StrTime(lefttime) ''剩余时间
Me.Text = "filecopy" & Space(10) & "速度 M/s:" & speed
Else
LProcessedBytes.Text = "文件大小:0"
End If
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Information)
End Try


End Sub
Private Function StrTime(ByVal T As Double) As String
Dim H As Double, M As Double

H = T \ 3600 : T = T - H * 3600
M = T \ 60 : T = T - M * 60
If H > 0 Then StrTime = H & " 时"
If H > 0 Or M > 0 Then StrTime = StrTime & M & " 分"
StrTime = StrTime & Format(T, "#0.00") & " 秒"
End Function

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If fcompleted = True Then
fExit = True
fCancel = True
e.Cancel = False ''如果复制完成,直接可以退出
Else
If fExit = False Then
Dim ss As String
ss = "目前文件:" & "" & Chr(13) & _
"要取消复制吗?" & Chr(13) & Chr(13) & _
"要立即结束复制,请单击是" & """是""" & Chr(13) & "要继续复制,请单击" & """否""" & "。"

If MsgBox(ss, MsgBoxStyle.Information + MsgBoxStyle.YesNo, "复制工具") = MsgBoxResult.Yes Then
fExit = True
fCancel = True
Else
fExit = False
fCancel = False
e.Cancel = True ''取消关闭
End If
End If
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LfileProcessed.Text = 0
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Format(Now, "HH:mm") = "07:00" Then
Call Button1.PerformClick()
End If
End Sub
End Class


这篇关于如何使用vb.net制作类似Windows ntbackup的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆