VB.net如何复制一个文件夹下所有同名文件到另一文件夹
比如说一个文件夹下的所有叫zz的文件,如zz.doczz.txt等等全部复制到另一文件夹?该如何编程实现?补充一下:复制到另一文件夹还要重新命名为另一文件名...
比如说一个文件夹下的所有叫zz的文件,如zz.doc zz.txt 等等 全部复制到另一文件夹?该如何编程实现?
补充一下:复制到另一文件夹还要重新命名为另一文件名 展开
补充一下:复制到另一文件夹还要重新命名为另一文件名 展开
展开全部
'这是VB的要先引用Microsoft Scripting RunTime,下面的例子是找叫cmd.xxx的文件的
Private Sub Command1_Click()
Dim m_objFSO As New FileSystemObject
Dim objFolder As Scripting.Folder '文件夹对象
Dim objFile As Scripting.File '文件对象
Set objFolder = m_objFSO.GetFolder("c:/test")
For Each objFile In objFolder.Files
Dim filenames() As String
filenames = Split(objFile.Name, ".")
If filenames(0) = "cmd" Then
FileCopy objFile.Path, "c:/TestCMD/" & "newName." & filenames(1)
End If
Next objFile
End Sub
-----------------------------------这是VB.net的--------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim files() As String
files = System.IO.Directory.GetFiles("C:/test")
For i = 0 To files.Length - 1
Dim filenames() As String
filenames = files(i).Substring(files(i).LastIndexOf("\") + 1).Split(".")
If filenames(0) = "cmd" Then
FileCopy(files(i), "c:/TestCMD/" & "newName." & filenames(1))
End If
Next
End Sub
Private Sub Command1_Click()
Dim m_objFSO As New FileSystemObject
Dim objFolder As Scripting.Folder '文件夹对象
Dim objFile As Scripting.File '文件对象
Set objFolder = m_objFSO.GetFolder("c:/test")
For Each objFile In objFolder.Files
Dim filenames() As String
filenames = Split(objFile.Name, ".")
If filenames(0) = "cmd" Then
FileCopy objFile.Path, "c:/TestCMD/" & "newName." & filenames(1)
End If
Next objFile
End Sub
-----------------------------------这是VB.net的--------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim files() As String
files = System.IO.Directory.GetFiles("C:/test")
For i = 0 To files.Length - 1
Dim filenames() As String
filenames = files(i).Substring(files(i).LastIndexOf("\") + 1).Split(".")
If filenames(0) = "cmd" Then
FileCopy(files(i), "c:/TestCMD/" & "newName." & filenames(1))
End If
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询