vb.net请教怎么把一个文件夹下所有txt文本移动到另一个文件夹里^_^ tks

如题所述

在窗体上添加2个文本框,1个按钮:
其中1个文本框用来输入:源文件夹,另1个文本框用来输入目标文件夹
1个按钮编写代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MySourceFolder As String
If Microsoft.VisualBasic.Right(TextBox1.Text, 1) = "\" Then
MySourceFolder = TextBox1.Text
Else
MySourceFolder = TextBox1.Text & "\"
End If
Dim MyDestFolder As String
If Microsoft.VisualBasic.Right(TextBox2.Text, 1) = "\" Then
MyDestFolder = TextBox2.Text
Else
MyDestFolder = TextBox2.Text & "\"
End If

Dim MyDir As New System.IO.DirectoryInfo(MySourceFolder)
Dim MyFiles() As System.IO.FileInfo = MyDir.GetFiles("*.txt")
For Each MyFile As System.IO.FileInfo In MyFiles
System.IO.File.Copy(MySourceFolder & MyFile.Name, MyDestFolder & MyFile.Name, True) '允许同名覆盖,否则为False
Next
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-06-24
文件移动在my.computer.filesysyem里面有吧,复制的话效率太低了