FSO文件对象介绍及常用函数 |
本文标签:FSO文件对象介绍及常用函数 FSO的意思是FileSystemObject,即文件系统对象 。FSO对象模型包含在Scripting 类型库 (Scrrun.Dll)中,它同时包含了Drive、Folder、File、FileSystemObject和TextStream五个对象,用来操作文件和文件夹十分方便 。 复制代码 代码如下: Function reName(sourceName,destName) dim oFso,oFile set oFso=server.createobject("Scripting.FileSystemObject") set oFile=oFso.getFile(Server.mappath(sourceName)) oFile.Name=destName Set oFso=Nothing Set oFile=Nothing End Function 删除文件 复制代码 代码如下: Function FSOdel(fileName) dim fso,f set fso = server.CreateObject("scripting.filesystemobject") f=server.MapPath(fileName) if fso.FileExists(f) then fso.DeleteFile f,true end if set f = nothing set fso = nothing End Function 替换文件中的字符串 复制代码 代码如下: Function FSOreplace(fileName,Target,repString)
Dim objFSO,objCountFile,FiletempData Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objCountFile = objFSO.OpenTextFile(Server.MapPath(fileName),1,True) FiletempData = objCountFile.ReadAll objCountFile.Close FiletempData=Replace(FiletempData,Target,repString) Set objCountFile=objFSO.CreateTextFile(Server.MapPath(fileName),True) objCountFile.Write FiletempData objCountFile.Close Set objCountFile=Nothing Set objFSO = Nothing End Function |