vb中如何将一个文件的所有东西复制到另一个文件夹

2024-05-13

1. vb中如何将一个文件的所有东西复制到另一个文件夹

Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long '是复制、删除还是移动
pFrom As String '源文件夹或文件
pTo As String '目的文件夹或文件
fFlags As Integer '是否显示个子对话框
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Sub Command1_Click()
Dim SHFileOp As SHFILEOPSTRUCT
SHFileOp.wFunc = &H2
SHFileOp.pFrom = "C:\xyz.z" '源文件夹或文件
SHFileOp.pTo = "D:\aaz.z"   '目的文件夹或文件
SHFileOp.fFlags = &H40 + &H1
SHFileOperation SHFileOp
End Sub

vb中如何将一个文件的所有东西复制到另一个文件夹

2. VB中怎么将一个文件复制到指定文件夹

Dim fs   ' 先声明一个变体型
Set fs = CreateObject("Scripting.FileSystemObject")   '创建文件系统对象fs
 fs.copyfile "D:\copyto.txt", "E:\"    '使用该对象的copyfile方法将源文件复制到目标文件

3. vb中如何将一个文件的所有东西复制到另一个文件夹

wFunc As Long '是复制、删除还是移动 pFrom As String '源文件夹或文件 pTo As String '目的文件夹或文件 fFlags As Integer '是否显示个子对话框 fAborted As Boolean hNameMaps As Long sProgress As String End Type Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long Private Sub Command1_Click() Dim SHFileOp As SHFILEOPSTRUCT SHFileOp.wFunc = &H2 SHFileOp.pFrom = "C:\xyz.z" '源文件夹或文件 SHFileOp.pTo = "D:\aaz.z" '目的文件夹或文件 SHFileOp.fFlags = &H40 + &H1 SHFileOperation SHFileOp End Sub

vb中如何将一个文件的所有东西复制到另一个文件夹

4. VB语言搜索指定文件夹复制文件

'我没有z盘,自己修改一下'添加2个command,1个list
Option Explicit
Dim sourcepath As String, targetpath As String
Private Sub Command1_Click()
    Dim s
    targetpath = targetpath & IIf(Right(targetpath, 1) = "\", "", "\")
    If Dir(targetpath, vbDirectory) = "" Then
        MsgBox "无效的源文件目录!"
        Exit Sub
    End If
    If List1.ListIndex >= 0 Then
        s = Split(List1.List(List1.ListIndex), "\")
        FileCopy List1.List(List1.ListIndex), targetpath & s(UBound(s))
    End If
End Sub
Private Sub Command2_Click()
    List1.Clear
    sourcepath = sourcepath & IIf(Right(sourcepath, 1) = "\", "", "\")
    If Dir(sourcepath, vbDirectory) = "" Then
        MsgBox "无效的源文件目录!"
        Exit Sub
    End If
    Dim s As String
    s = Dir(sourcepath, vbDirectory)
    Do While s  ""
        If s  "." And s  ".." Then
            List1.AddItem sourcepath & s
        End If
        s = Dir()
    Loop
End Sub
Private Sub Form_Load()
    sourcepath = "c:\cip3"
    targetpath = "d:\cip3"
    Command1.Caption = "复制"
    Command2.Caption = "搜索"
End Sub

5. vb6 搜索文件并复制

Private Sub sosuofile(MyPath As String)
Dim Myname As String
Dim dir_i() As String
Dim i, idir As Long
If Right(MyPath, 1)  "\" Then MyPath = MyPath + "\"
Myname = Dir(MyPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
Do While Myname  ""
If Myname  "." And Myname  ".." Then
If (GetAttr(MyPath & Myname) And vbDirectory) = vbDirectory Then '如果找到的是目录
idir = idir + 1
ReDim Preserve dir_i(idir) As String
dir_i(idir - 1) = Myname
Else:
If Right(Myname, 3) = "swf" Then
List1.AddItem MyPath & Myname   '添加到列表
End If
End If
End If
Myname = Dir '搜索下一项
Loop
For i = 0 To idir - 1
Call sosuofile(MyPath + dir_i(i))
Next i
ReDim dir_i(0) As String
End Sub

vb6 搜索文件并复制

6. vb 把一个文件复制到另一个文件夹中,并且改名

Name "c:\123.exe" As "c:\456.exe" 
或
Name "c:\123.exe" As "e:\456.exe"

7. VB.net如何复制一个文件夹下所有同名文件到另一文件夹

'这是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

VB.net如何复制一个文件夹下所有同名文件到另一文件夹

8. vb2010如何复制整个文件夹包括里面的子文件夹和文件到另一个路径

用cmd命令xcopy更简单些,在·至于在vb2010里面,就用 shell "xcopy 源文件夹 目标文件夹 /e /y"