你可以先检测该目录是否存在,如果不存则提示信息 然后建立 引用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
* 首先判断目录和文件是否存在 if Dir d:\bak\xc.mdb then * c存在的话执行拷贝 filecopy c:\xcgt1\xc.mdb,d:\bak\xc.bak else *不存在的话创建目录 .... end if
我试过拉,先不判断,就直接拷贝就失败了! Dim Exists As Boolean, CreateIt Dim fso As New FileSystemObject FileCopy "c:\xcgt1\xc.frx", "d:\bak\"抱错提示:路径未找到!路径我看过了,没问题啊,哪里出错了?
引用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
if Dir d:\bak\xc.mdb then
* c存在的话执行拷贝
filecopy c:\xcgt1\xc.mdb,d:\bak\xc.bak
else
*不存在的话创建目录
....
end if
Dim Exists As Boolean, CreateIt
Dim fso As New FileSystemObject
FileCopy "c:\xcgt1\xc.frx", "d:\bak\"抱错提示:路径未找到!路径我看过了,没问题啊,哪里出错了?
FileCopy "c:\xcgt1\xc.frx", "d:\bak\xc.frx"!
MsgBox a
FileCopy "c:\xcgt1\xc.frx", "d:\bak\xc.frx"
如果试图复制一个打开的文件将会出错