首页 /编程语言和算法/VB6/VBA/ASP
 VB6 文件拷贝子程序 f_FileCopy(strFN$, strFN2$)
2025年4月7日 15:36

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

Private Function f_FileCopy(strFN$, strFN2$) As Boolean
    If Dir(strFN2) = "" Then
        MsgBox "没找到 " & strFN2, vbCritical, "失败"
        f_FileCopy = False
        Exit Function
    End If
    
    If Dir(strFN) <> "" Then Kill strFN
    DoEvents
    FileCopy strFN2, strFN  '重命名
    f_FileCopy = True
End Function

Private Sub Command1_Click()
    Dim strFN$, strFN2$
    strFN = App.Path & "\abc.txt"
    strFN2 = strFN & ".bak"
    If f_FileCopy(strFN, strFN2) = False Then Exit Sub
    
    MsgBox "拷贝成功", vbInformation, "成功"
End Sub


 
全部回复(0)
首页 | 电脑版 |