vb2010怎样在文件夹中建一个txt
2017-02-20
展开全部
在窗体上添加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个文本框用来输入:源文件夹,另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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |