VB.Net 2005 WinFrom 文件上传程序...

前端之家收集整理的这篇文章主要介绍了VB.Net 2005 WinFrom 文件上传程序...前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

VB.Net 2005 WinFrom 上传文件程序

程序代码: AppUpdater.vb

Imports System.IO

Public Class AppUpdater

Private Total As Integer = 0

Private FileNumber As Integer = 0

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

'Me.ProgressBar1.Maximum = Directory.CreateDirectory(Me.TextBox1.Text).

Dim DirInfo_source As New DirectoryInfo(Me.Tbx_Source.Text)

Total = 0

FileNumber = Me.GetFilesCount(DirInfo_source)

Me.ProgressBar1.Maximum = FileNumber

Me.CopyDirector(Me.Tbx_Source.Text,Me.Tbx_Dest.Text)

End Sub

Public Sub CopyDirector(ByVal SourceDirName As String,ByVal DestdirName As String)

If (Not Directory.Exists(DestdirName)) Then

Directory.CreateDirectory(DestdirName)

File.SetAttributes(DestdirName,File.GetAttributes(SourceDirName))

End If

If (DestdirName(DestdirName.Length - 1) <> Path.DirectorySeparatorChar) Then

DestdirName = DestdirName + Path.DirectorySeparatorChar

Dim files As String() = Directory.GetFiles(SourceDirName)

For Each l_file As String In files

File.Copy(l_file,DestdirName + Path.GetFileName(l_file),True)

File.SetAttributes(DestdirName + Path.GetFileName(l_file),FileAttributes.Normal)

Total = Total + 1

Me.lblStatus.BackColor = Me.ProgressBar1.BackColor

Me.ProgressBar1.Value = Total

If (FileNumber = 0) Then

lblStatus.Text = "已完成 100%"

Else

lblStatus.Text = "已完成 " + (Math.Round(CType((100 * Total / FileNumber),System.Double),0)).ToString() + "%"

End If

Me.Label_From.Text = l_file

Me.Label_To.Text = DestdirName + Path.GetFileName(l_file)

lblStatus.Refresh()

Label_From.Refresh()

Label_To.Refresh()

Next

Dim dirs As String() = Directory.GetDirectories(SourceDirName)

For Each dir As String In dirs

Me.Refresh()

Me.Focus()

Me.Activate()

CopyDirector(dir,DestdirName + Path.GetFileName(dir))

Next

End If

End Sub

Public Function GetFilesCount(ByVal dirInfo As System.IO.DirectoryInfo) As String

Dim totalFile As Integer = 0

totalFile += dirInfo.GetFiles().Length

For Each subdir As System.IO.DirectoryInfo In dirInfo.GetDirectories

totalFile += GetFilesCount(subdir)

Next

Return totalFile

End Function

End Class

---效果图---

原文链接:https://www.f2er.com/vb/263194.html

猜你在找的VB相关文章