vb.net 文件夹实现移动 并显示进度条,richtextbox1显示移动的文件名

vb.net 文件夹实现移动 并显示进度条,richtextbox1显示移动的文件名,第1张

概述利用线程,和计时器,Function GetFolderSize从网上借鉴的,IO类只支持不同分区移动,所以移动目录只能在相同分区,设计界面如图, 如: d:/a  d:/b(空目录) 代码如下   Imports System.IO Imports System.Threading Public Class Form2     Dim SourceDir, DestDir As String  

利用线程,和计时器,Function GetFolderSize从网上借鉴的,IO类只支持不同分区移动,所以移动目录只能在相同分区,设计界面如图,

如: d:/a d:/b(空目录)

代码如下

imports System.IO
imports System.Threading

Public Class Form2
Dim SourceDir,DestDir As String
Dim SourceLen As Integer

'返回文件夹大小
Private Function GetFolderSize(ByVal DirPath As String,Optional ByVal IncludeSubFolders As Boolean = True) As Long
Dim lngDirsize As Long
Dim objfileInfo As fileInfo
Dim objdir As DirectoryInfo = New DirectoryInfo(DirPath)
Dim obJsubFolder As DirectoryInfo
Try
For Each objfileInfo In objdir.Getfiles()
lngDirsize += objfileInfo.Length
Next
If IncludeSubFolders Then
For Each obJsubFolder In objdir.GetDirectorIEs()
lngDirsize += GetFolderSize(obJsubFolder.Fullname)
Next
End If
Catch
End Try
Return lngDirsize
End Function

Private Sub button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button1.Click
Dim T As New Thread(AddressOf DirMove)

CheckForIllegalCrossthreadCalls = False

SourceDir = TextBox1.Text
DestDir = TextBox2.Text

SourceLen = GetFolderSize(SourceDir)

Progressbar1.Value = 0
Timer1.Interval = 100
Timer1.Start()
T.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Timer1.Tick
If Directory.Exists(DestDir) = False Then Exit Sub
If SourceLen <> 0 Then
Progressbar1.Value = Math.Round(GetFolderSize(DestDir) / SourceLen,2) * 100
End If

End Sub

Private Sub DirMove()
Me.Text = "正在移动..."
Directory.Move(SourceDir,DestDir)
Me.Text = "移动完成!"
Progressbar1.Value = 100
RichTextBox1.Text += DestDir & Environment.Newline
End Sub

Private Sub Dircopy()
My.Computer.fileSystem.copyDirectory(SourceDir,DestDir,True,fileIO.UICancelOption.Donothing)
End Sub

Private Sub button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button2.Click
Dim T As New Thread(AddressOf Dircopy)

CheckForIllegalCrossthreadCalls = False

SourceDir = TextBox1.Text
DestDir = TextBox2.Text

SourceLen = GetFolderSize(SourceDir)

Progressbar1.Value = 0
Timer1.Interval = 100
Timer1.Start()
T.Start()
End Sub

Private Sub button3_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button3.Click
Dim a As New ArrayList
a.Add(".MP3")
Dim b As New ArrayList
Dim c As New Hashtable

clsUtil.findDirectory("D:/a",a,b,c)
End Sub
End Class

总结

以上是内存溢出为你收集整理的vb.net 文件夹实现移动 并显示进度条,richtextbox1显示移动的文件名全部内容,希望文章能够帮你解决vb.net 文件夹实现移动 并显示进度条,richtextbox1显示移动的文件名所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1294123.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存