登录123 | 账号: 密码: 今天是: 加入收藏 返回首页 

同城供应求购,商机就在身边 免费企业商铺,免费发布商机 关注商业资讯,把握商业机会 同城库存二手,晒出您的宝贝,淘进新的宝贝
全国企业黄页大全,加入即可得到推广
返回同城123首页
同城123信息网,最全最专业的同城分类信息网
同城生活贴吧,贴出生活的精彩 同城房屋租售,卖房、买房、租房、出租 同城招聘求职,优秀人才/高薪岗位等您来 同城婚恋交友,寻找你的TA
免费无极限,广告任意发
供应求购 免费商铺 商业资讯 库存二手 黄页大全 生活贴吧 房屋租售 招聘求职 婚恋交友 自助广告

asp之FSO函数大全
发布时间:2010/10/22 9:51:25 发布人:网络游民 点击:173
asp之FSO大全
对于一个支持asp和fso的空间来说有了fso一切变得简单多了
我也是个新手写了一些代码供大家学习研究用
首先看支持fso组件吗
<%
'FSO组件名称
dim FSObject
FSObject="Scripting.FileSystemObject"
'=========================================================
'◆是否支持组件
'=========================================================
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
if IsObjInstalled(FSObject) then
response.write "√"
else
response.write "×"
end if%>
-------------------------------------------------------
<%
'=========================================================
'◆是否支持组件
'=========================================================
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
'=========================================================
'fso 操作
'=========================================================
'◆检查某一目录是否存在
'=========================================================
Function CheckDir(FolderPath)
folderpath=Server.MapPath(".")&"\"&folderpath
Set fso= CreateObject(FSObject)
If fso.FolderExists(FolderPath) then
CheckDir = True
Else
CheckDir = False
End if
Set fso= nothing
End Function
'=========================================================
'◆ 根据指定名称生成目录
'=========================================================
Function MakeNewsDir(foldername)
dim fs0
Set fso= CreateObject(FSObject)
Set fs0= fso.CreateFolder(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=request.ServerVariables("APPL_PHYSICAL_PATH")&folderpath
fso.DeleteFolder(path)
Set fso = nothing
end Function
'=========================================================
'◆ 更改文件夹名称 ◆
'=========================================================
Function moveFolder(foldername,newfoldername)
isfso
Set fso = CreateObject(FSObject)
fso.moveFolder ""&request.ServerVariables("APPL_PHYSICAL_PATH")&"\"&foldername&"" ,""&request.ServerVariables("APPL_PHYSICAL_PATH")&"\"&newfoldername&""
Set fso =nothing
End Function
'=========================================================
'◆ 删除指定文件 ◆
'=========================================================
Function DeleteFile(file)
Set fso = CreateObject(FSObject)
fso.DeleteFile request.ServerVariables("APPL_PHYSICAL_PATH")&file
Set fso = nothing
End Function
'=========================================================
'◆ 备份指定文件 ◆
'=========================================================
Function CopyFile(oldfile,newfile)
Set fso = CreateObject(FSObject)
On Error Resume Next
Set fso=Server.CreateObject(FSObject)
oldfile=Server.MapPath(oldfile)
if Err.Number>0 Then call alert("原路径错误!","")
newfile=Server.MapPath(newfile)
if Err.Number>0 Then call alert("新路径错误!","")
fso.CopyFile oldfile,newfile'覆盖原来的文件
if Err.Number>0 Then call alert(Err.Description,"")
Set fso=nothing
End Function
'=========================================================
'◆ 转移指定文件 ◆
'=========================================================
Function MoveFile(oldfile,newfile)
Set fso = CreateObject(FSObject)
On Error Resume Next
Set fso=Server.CreateObject(FSObject)
oldfile=Server.MapPath(oldfile)
if Err.Number>0 Then call alert("原路径错误!","")
newfile=Server.MapPath(newfile)
if Err.Number>0 Then call alert("新路径错误!","")
'fso.MoveFile oldfile,newfile'不能覆盖原来的文件
fso.MoveFile "d:\o\data\test.txt","d:\o\databackup\test3.txt"
if Err.Number>0 Then call alert(Err.Description,"")
Set fso=nothing
End Function
'=========================================================
'◆ 读取文件代码 ◆
'=========================================================
Function loadfile(file)'读取文件
dim ftemp
Set fso = CreateObject(FSObject)
Set ftemp=fso.OpenTextFile(Server.MapPath(""&file&""), 1)
loadfile=ftemp.ReadAll
ftemp.Close
fso.close
set fso=nothing
End Function
'=========================================================
'◆ 根据代码生成文件 ◆
'=========================================================
'========================================
'■file生成文件名
'■code文件的代码
'========================================
Function savefile(file,code)'保存文件
dim MyFile
Set fso = CreateObject(FSObject)
Set MyFile = fso.CreateTextFile(Server.mapPath(file), True)
MyFile.WriteLine(code)
MyFile.Close
set MyFile=nothing
End Function
'=========================================================
'◆ 压缩数据库 ◆
'=========================================================
'========================================
'■dbPath数据文件路径
'■boolIs97 access97压缩
'========================================
Function CompactDB(dbPath,boolIs97)
dim strDBPath,fso,Engine
dbPath=server.mappath(dbpath)
strDBPath = left(dbPath,instrrev(DBPath,"\"))
Set fso = CreateObject(FSObject)
If fso.FileExists(dbPath) Then
Set Engine = CreateObject("JRO.JetEngine")
If boolIs97 = "True" Then
dim JET_3X
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb;" _
&"Jet OLEDB:Engine Type=" & JET_3X
Else
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
"Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database password="&dbpw&";Data Source="&strDBPath&"temp.mdb"
End If
fso.CopyFile strDBPath & "temp.mdb",dbpath
fso.DeleteFile(strDBPath&"temp.mdb")
Set fso = nothing
Set Engine = nothing
CompactDB="当前数据库,已经压缩成功!"
Else
CompactDB="数据库名称或路径不正确. 请重试!"
End If
End Function
%>

 fso教程网址: 
回复此帖
123发布网广告位【218】 123发布网广告位【219】
 ※ 发布回复   ↓请遵循123发布网同城生活贴吧/论坛发帖规则;↓寻一夜情、包养、招嫖类信息的一律全部删除,并报公安备案↓  
回复标题:  
回复内容:
上传图片:
验 证 码:  

123发布网广告位【220】 123发布网广告位【221】
网站首页 | 关于我们 | 广告业务 | 关于VIP | 免责声明 | 联系我们 | 设为首页 | 加入收藏 | 意见反馈 | 网站建设
123发布网 版权所有 www.123fbw.com  联系电话:18331151646  QQ:1016964448
 CopyRight © 2007-2016 All Right Reserved  联系站长  津ICP备10002728号  统计: