If Err.number<>0 Then
Err.Clear
DbExists = false
else
DbExists = True
End If
set c = nothing
End function
''取当前真实路径
Private function AppPath()
AppPath = Server.MapPath("./")
If Right(AppPath,1) = "\" THen
AppPath = AppPath
ELse
AppPath = AppPath & "\"
End if
End function
''删除一个数据库文件
Public function DeleteDBFile(filespec)
filespec = AppPath() & filespec
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.number<>0 Then
ErrMsg("删除文件发生错误!请查看错误信息:" & Err.number & " " & Err.Description & "<br>")
Err.Clear
DeleteDBFile = False
End If
If DbExists(filespec) THen
call fso.DeleteFile(filespec)
DeleteDBFile = True
Else
ErrMsg("删除文件发生错误!请查看错误信息:" & Err.number & " " & Err.Description & "<br>")
DeleteDBFile = False
Exit Function
End if
Set fso = Nothing
End function
''修改一个数据库名
Public function RenameDBFile(filespec1,filespec2)
filespec1 = AppPath() & filespec1:filespec2 = AppPath() & filespec2
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.number<>0 Then
ErrMsg("修改文件名时发生错误!请查看错误信息:" & Err.number & " " & Err.Description)
Err.Clear
RenameDBFile = False
End If
If DbExists(filespec1) THen
call fso.CopyFile(filespec1,filespec2,True)
call fso.DeleteFile(filespec1)
RenameDBFile = True
Else
ErrMsg("源文件不存在!!!")
RenameDBFile = False
Exit Function
End if
Set fso = Nothing
End function
''压缩数据库
Public Function CompactDBFile(strDBFileName)
Dim Jet_Conn_Partial
Dim SourceConn
Dim DestConn
Dim oJetEngine
Dim oFSO
Jet_Conn_Partial = "Provider=Microsoft.Jet.OLEDB.4.0; Data source="
SourceConn = Jet_Conn_Partial & AppPath() & strDBFileName
DestConn = Jet_Conn_Partial & AppPath() & "Temp" & strDBFileName
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oJetEngine = Server.CreateObject("JRO.JetEngine")
With oFSO
If Not .FileExists( AppPath() & strDBFileName) Then
ErrMsg ("数据库文件未找到!!!!" )
Stop
CompactDBFile = False
Exit Function
Else
If .FileExists( AppPath() & "Temp" & strDBFileName) Then
ErrMsg("不知道的错误!!!")
.DeleteFile ( AppPath() & "Temp" & strDBFileName)
CompactDBFile = False
Exit Function
End If