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:odatatest.txt","d:odatabackuptest3.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
%>

时间: 2024-08-08 01:46:45

asp之FSO大全的相关文章

ASP错误提示大全

ASP错误提示大全 MicrosoftVBScript语法错误(0×800A03E9)–>内存不足MicrosoftVBScript语法错误(0×800A03EA)–>语法错误 MicrosoftVBScript语法错误(0×800A03EB)–>缺少?':' MicrosoftVBScript语法错误(0×800A03ED)–>缺少?'(' MicrosoftVBScript语法错误(0×800A03EE)–>缺少?')' MicrosoftVBScript语法错误(0×8

asp教程:fso获取的文件扩展名

asp教程:fso获取的文件扩展名 这个例子演示如何使用GetExtensionName方法得到的文件扩展名的最后部分中指定的路径. 来看个获取文章扩展名的实例教程吧. <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Response.Write("The file extension of the file 3dgarro is: ")

asp教程:fso获取的名称指定的驱动器

asp教程:fso获取的名称指定的驱动器 这个例子演示如何使用GetDriveName方法获取的名称指定的驱动器. <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") p=fs.GetDriveName("c:winntcursors3dgarro.cur") Response.Write("The drive name is: &

asp利用fso生成html页面

asp利用fso生成html页面,此文章是我大二时写的了,就是利用asp自带组件fso来进行用户文件上传时就生成html文件用了,它也很好的判断文件名称是否存在了,等提示 <% dim path,filename,filetype,fileconten,fso path=request("path") filename=html_encode(request("filename")) filecontent=request("filecontent&

ASP 系列函数大全(1)

函数    ASP函数大全   ASP函数与VBSCRIPT类似,以下举一些常用的函数      Array()      函数返回一个数组      表达式 Array(list)      允许数据类型: 字符,数字均可      实例: <%      Dim myArray()      For i = 1 to 7      Redim Preserve myArray(i)      myArray(i) = WeekdayName(i)      Next      %>   

ASP 系列函数大全

ASP函数大全 ASP函数与VBSCRIPT类似,以下举一些常用的函数 Array() 函数返回一个数组 表达式 Array(list) 允许数据类型: 字符,数字均可 实例: <% Dim myArray() For i = 1 to 7 Redim Preserve myArray(i) myArray(i) = WeekdayName(i) Next %> 返回结果: 建立了一个包含7个元素的数组myArray myArray("Sunday","Monda

ASP中FSO的神奇功能

fso|fso 转帖 FSO 模型对象 Drive Object:驱动器对象 供存取磁盘或者网络驱动器 FileSystemObject Object:文件系统对象 供存取计算机的文件系统 Folder Object:文件夹对象 供存取文件夹的所有属性 TextStream Object:文本流对象 供存取文件内容 你可以使用上面的对象做计算机上的任何事情,也包括破坏活动 ;-( 所以,请小心使用FSO.在web环境中,存储信息是非常重要的,比如用户信息,日志文件,等等.FSO提供了一个强大且简

ASP中FSO对象对IIS WEB服务器数据安全的威胁及对策

fso|iis|web|web服务|web服务器|安全|对象|数据 scripting.filesystemobject 对象是由 scrrun.dll 提供的许多供 vbscript/jscript 控制的 com 对象之一.scripting.filesystemobject 提供了非常便利的文本文件和文件目录的访问,但是同时也对 iis web 服务器数据安全造成了一定的威胁. filefinder 的代码很简单,由3 个函数和 30 行左右的顺序代码构成. 最关键的是 findfiles

ASP中FSO的神奇功能 - 简介

fso 作 者 : 甘冀平 ; 原文出处:http://www.15seconds.com/Issue/000816.htm 在ASP中,FSO的意思是File System Object,即文件系统对象. 我们将要操纵的计算机文件系统,在这里是指位于web服务器之上.所以,确认你对此拥有合适的权限.理想情况下,你可以在自己的机器上建立一个web服务器,这样就能方便地进行测试.如果运行于Windows平台,请试一试微软公司的免费个人Web服务器PWS. FSO 模型对象 Drive Object