查看: 68  |  回复: 0
  VB6 拷贝文件 FileCopy sourceFile, destinationFile
楼主
发表于 2025年3月3日 19:26

新建From1(窗体),新建Command1(按钮CommandButton),代码:

Private Sub Command1_Click()
    Dim sourceFile As String
    Dim destinationFile As String
    
    ' 设置源文件路径
    sourceFile = "C:\SourceFolder\SourceFile.txt"
    ' 设置目标文件路径
    destinationFile = "D:\DestinationFolder\DestinationFile.txt"
    
    On Error Resume Next ' 忽略错误,后续可根据 Err.Number 判断具体错误
    FileCopy sourceFile, destinationFile
    
    If Err.Number = 0 Then
        MsgBox "文件复制成功!"
    Else
        MsgBox "文件复制失败,错误代码: " & Err.Number & ",错误描述: " & Err.Description
    End If
    Err.Clear ' 清除错误信息
End Sub


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com