asp

位置:IT落伍者 >> asp >> 浏览文章

asp之FSO大全


发布日期:2021年02月04日
 
asp之FSO大全

对于一个支持asp和fso的空间来说有了fso一切变得简单多了

我也是个新手写了一些代码供大家学习研究用

首先看支持fso组件吗

<%
FSO组件名称
dim FSObject
FSObject="ScriptingFileSystemObject"

=========================================================
◆是否支持组件
=========================================================
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err =
Dim xTestObj
Set xTestObj = ServerCreateObject(strClassString)
If = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err =
End Function

if IsObjInstalled(FSObject) then
responsewrite "√"
else
responsewrite "×"
end if%>

<%
=========================================================
◆是否支持组件
=========================================================
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err =
Dim xTestObj
Set xTestObj = ServerCreateObject(strClassString)
If = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err =
End Function
=========================================================
fso 操作
=========================================================
◆检查某一目录是否存在
=========================================================
Function CheckDir(FolderPath)
folderpath=ServerMapPath("")&""&folderpath
Set fso= CreateObject(FSObject)
If fsoFolderExists(FolderPath) then
CheckDir = True
Else
CheckDir = False
End if
Set fso= nothing
End Function
=========================================================
◆ 根据指定名称生成目录
=========================================================
Function MakeNewsDir(foldername)
dim fs
Set fso= CreateObject(FSObject)
Set fs= fsoCreateFolder(foldername)
Set fso = nothing
End Function
=========================================================
◆ 如果文件夹不存在则建立新文件夹 ◆
=========================================================
Function checkFolder(folderpath)
If CheckDir(folderpath) = false Then如果文件夹不存在
MakeNewsDir(folderpath)就建一个文件夹
end if
end Function
=========================================================
◆ 删除文件夹 ◆
=========================================================
Function DeleteFoldera(folderpath)
dim path
Set fso = CreateObject(FSObject)
path=requestServerVariables("APPL_PHYSICAL_PATH")&folderpath
fsoDeleteFolder(path)
Set fso = nothing
end Function
=========================================================
◆ 更改文件夹名称 ◆
=========================================================
Function moveFolder(foldernamenewfoldername)
isfso
Set fso = CreateObject(FSObject)
fsomoveFolder ""&requestServerVariables("APPL_PHYSICAL_PATH")&""&foldername&"" ""&requestServerVariables("APPL_PHYSICAL_PATH")&""&newfoldername&""
Set fso =nothing
End Function
=========================================================
◆ 删除指定文件 ◆
=========================================================
Function DeleteFile(file)
Set fso = CreateObject(FSObject)
fsoDeleteFile requestServerVariables("APPL_PHYSICAL_PATH")&file
Set fso = nothing
End Function
=========================================================
◆ 备份指定文件 ◆
=========================================================
Function CopyFile(oldfilenewfile)
Set fso = CreateObject(FSObject)
On Error Resume Next
Set fso=ServerCreateObject(FSObject)
oldfile=ServerMapPath(oldfile)
if ErrNumber> Then call alert("原路径错误!""")
newfile=ServerMapPath(newfile)
if ErrNumber> Then call alert("新路径错误!""")
fsoCopyFile oldfilenewfile覆盖原来的文件
if ErrNumber> Then call alert(ErrDescription"")
Set fso=nothing
End Function
=========================================================
◆ 转移指定文件 ◆
=========================================================
Function MoveFile(oldfilenewfile)
Set fso = CreateObject(FSObject)
On Error Resume Next
Set fso=ServerCreateObject(FSObject)
oldfile=ServerMapPath(oldfile)
if ErrNumber> Then call alert("原路径错误!""")
newfile=ServerMapPath(newfile)
if ErrNumber> Then call alert("新路径错误!""")
fsoMoveFile oldfilenewfile不能覆盖原来的文件
fsoMoveFile "d:odatatesttxt""d:odatabackuptesttxt"
if ErrNumber> Then call alert(ErrDescription"")
Set fso=nothing
End Function
=========================================================
◆ 读取文件代码 ◆
=========================================================
Function loadfile(file)读取文件
dim ftemp
Set fso = CreateObject(FSObject)
Set ftemp=fsoOpenTextFile(ServerMapPath(""&file&"") )
loadfile=ftempReadAll
ftempClose
fsoclose
set fso=nothing
End Function
=========================================================
◆ 根据代码生成文件 ◆
=========================================================
========================================
■file生成文件名
■code文件的代码
========================================
Function savefile(filecode)保存文件
dim MyFile
Set fso = CreateObject(FSObject)
Set MyFile = fsoCreateTextFile(ServermapPath(file) True)
MyFileWriteLine(code)
MyFileClose
set MyFile=nothing
End Function
=========================================================
◆ 压缩数据库 ◆
=========================================================
========================================
■dbPath数据文件路径
■boolIs access压缩
========================================
Function CompactDB(dbPathboolIs)
dim strDBPathfsoEngine
dbPath=servermappath(dbpath)
strDBPath = left(dbPathinstrrev(DBPath""))
Set fso = CreateObject(FSObject)
If fsoFileExists(dbPath) Then
Set Engine = CreateObject("JROJetEngine")
If boolIs = "True" Then
dim JET_X
EngineCompactDatabase "Provider=MicrosoftJetOLEDB;Data Source=" & dbpath _
"Provider=MicrosoftJetOLEDB;Data Source=" & strDBPath & "tempmdb;" _
&"Jet OLEDB:Engine Type=" & JET_X
Else
EngineCompactDatabase "Provider=MicrosoftJetOLEDB;Data Source=" & dbpath _
"Provider=MicrosoftJetOLEDB;Jet OLEDB:Database password="&dbpw&";Data Source="&strDBPath&"tempmdb"
End If
fsoCopyFile strDBPath & "tempmdb"dbpath
fsoDeleteFile(strDBPath&"tempmdb")
Set fso = nothing
Set Engine = nothing
CompactDB="当前数据库已经压缩成功!"
Else
CompactDB="数据库名称或路径不正确 请重试!"
End If
End Function
%>

上一篇:asp入门实例-读取数据库程序

下一篇:ASP request.from 教程