我想按command按钮后,自动将c:\xcgt1\xc.mdb拷贝到d:\bak里,语句该怎么写?(如d里没有bak目录可以提示是否创建信息,如d:\bak中已有xc.mdb会提示是否覆盖文件),请赐教!

解决方案 »

  1.   

    你可以先检测该目录是否存在,如果不存则提示信息 然后建立
    引用Microsoft Script Control 1.0
           Microsoft Scripting Runtime
    Function CheckFolder(FoldrPath As String) As Boolean
        Dim Exists As Boolean, CreateIt
        Dim fso As New FileSystemObject       If (fso.FolderExists(FoldrPath)) Then
                Exits = True
           Else
                Exits = False
                '不存在则建立
       if msgbox("文件夹不存在,是否建立?",vbyesno,app.title)=vbyes then            Set CreateIt = fso.CreateFolder(FoldrPath)
        end if
          End If
          '值返回函数
          CheckFolder = Exits
    End Function
    然后在目标文件夹存在的情况下检测文件是否存在..
    filecopy 源文件,目标文件
    filecopy c:\xcgt1\xc.mdb,d:\bak\xc.bak
      

  2.   

    * 首先判断目录和文件是否存在
    if Dir d:\bak\xc.mdb then
       * c存在的话执行拷贝
       filecopy c:\xcgt1\xc.mdb,d:\bak\xc.bak
    else
    *不存在的话创建目录
    ....
    end if
      

  3.   

    我试过拉,先不判断,就直接拷贝就失败了!
    Dim Exists As Boolean, CreateIt
    Dim fso As New FileSystemObject
    FileCopy "c:\xcgt1\xc.frx", "d:\bak\"抱错提示:路径未找到!路径我看过了,没问题啊,哪里出错了?
      

  4.   

    FileCopy "c:\xcgt1\xc.frx", "d:\bak\"改为
    FileCopy "c:\xcgt1\xc.frx", "d:\bak\xc.frx"!
      

  5.   

    eg :a = CheckFolder("d:\bak")
    MsgBox a
    FileCopy "c:\xcgt1\xc.frx", "d:\bak\xc.frx"
    如果试图复制一个打开的文件将会出错