ASP FSO操作文件复制文件重命名文件删除文件替换字符串文档格式.docx

上传人:b****4 文档编号:16813928 上传时间:2022-11-26 格式:DOCX 页数:9 大小:16.93KB
下载 相关 举报
ASP FSO操作文件复制文件重命名文件删除文件替换字符串文档格式.docx_第1页
第1页 / 共9页
ASP FSO操作文件复制文件重命名文件删除文件替换字符串文档格式.docx_第2页
第2页 / 共9页
ASP FSO操作文件复制文件重命名文件删除文件替换字符串文档格式.docx_第3页
第3页 / 共9页
ASP FSO操作文件复制文件重命名文件删除文件替换字符串文档格式.docx_第4页
第4页 / 共9页
ASP FSO操作文件复制文件重命名文件删除文件替换字符串文档格式.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

ASP FSO操作文件复制文件重命名文件删除文件替换字符串文档格式.docx

《ASP FSO操作文件复制文件重命名文件删除文件替换字符串文档格式.docx》由会员分享,可在线阅读,更多相关《ASP FSO操作文件复制文件重命名文件删除文件替换字符串文档格式.docx(9页珍藏版)》请在冰豆网上搜索。

ASP FSO操作文件复制文件重命名文件删除文件替换字符串文档格式.docx

DeleteFile删除一个文件

OpenTextFile打开文件并且返回TextStream对象,以便读取或者追加

重命名文件:

FunctionreName(sourceName,destName)

dimoFso,oFile

setoFso=server.createobject("

Scripting.FileSystemObject"

setoFile=oFso.getFile(Server.mappath(sourceName))

oFile.Name=destName

SetoFso=Nothing

SetoFile=Nothing

EndFunction

删除文件:

FunctionFSOdel(fileName)

dimfso,f

setfso=server.CreateObject("

scripting.filesystemobject"

f=server.MapPath(fileName)

iffso.FileExists(f)then

fso.DeleteFilef,true

endif

setf=nothing

setfso=nothing

替换文件中的字符串:

FunctionFSOreplace(fileName,Target,repString)

DimobjFSO,objCountFile,FiletempData

SetobjFSO=Server.CreateObject("

SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(fileName),1,True)

FiletempData=objCountFile.ReadAll

objCountFile.Close

FiletempData=Replace(FiletempData,Target,repString)

SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(fileName),True)

objCountFile.WriteFiletempData

SetobjCountFile=Nothing

SetobjFSO=Nothing

<

%

 

'

*******************************************************

函数名:

CreateFolder(sPath)

作用:

创建目录

参数:

sPath:

创建的相对目录路径

返回值:

成功true,失败false

response.Writecreatefolder("

/dgsunshine/UploadFile/demo1/"

FunctionCreateFolder(sPath)

OnErrorResumeNext

DimFso,Arrfolder,Folder,i,j 

IfsPath="

"

then

CreateFolder=False

ExitFunction

EndIf

IfLeft(sPath,1)="

/"

Then

Folder="

sPath=Mid(sPath,2,Len(sPath))

Else

./"

ifRight(sPath,1)="

thensPath=Left(sPath,Len(sPath)-1)

ArrFolder=Split(sPath,"

SetFso=Server.CreateObject("

Fori=0ToUbound(ArrFolder)

Ifi=0then

Folder=Folder&

ArrFolder(i)&

"

IfFso.folderExists(Server.MapPath(Folder))=Falsethen

response.Writeserver.MapPath(folder)

Fso.createFolder(Server.MapPath(Folder))

Next

SetFso=nothing

IfErr.Number<

>

0then

Err.clear()

CreateFolder=True

Endfunction

FunctiongetFile(paramFilePath)

SetFso_Read=fso.OpenTextFile(Server.MapPath(paramFilePath),1,false,-2)

getFile=Fso_Read.readall

SetFso_Read=Nothing

SetFso=Nothing

EndFunction

CreateFile(paramFileContent,paramFilePath)

创建文件

paramFileContent'

文件的内容

paramFilePath 

文件名(不包括路径)

FunctionCreateFile(paramFileContent,paramFilePath)

OnErrorResumeNext

DimFso,fWrite

SetfWrite=Fso.CreateTextFile(Server.Mappath(paramFilePath),true)

fWrite.writeparamFileContent

fWrite.close()

SetfWrite=nothing

IfErr.number<

0Then

CreateFile=False

Else

CreateFile=True

EndIf 

DelFile(FilePath)

删除文件

FilePath'

文件路径多个文件用"

|"

隔开

FunctionDelFile(FilePath)

Dimfso,arrFile,i

IfGetSafeStr(FilePath,"

)="

CreateFolder=false

ExitFunction

arrFile=Split(FilePath,"

fori=0toUBound(arrFile)

FilePath=arrFile(i)

IfFso.FileExists(Server.MapPath(FilePath))then

Fso.DeleteFileServer.MapPath(FilePath)

Setfso=nothing

IfErrthen

DelFile=false

DelFile=true

DelFolder(FolderPath)

删除目录

FolderPath'

目录路径'

多个目录用"

分隔

FunctionDelFolder(FolderPath)

DimFso,arrFolder,i

IfGetSafeStr(FolderPath,"

DelFolder=false

arrFolder=Split(FolderPath,"

Fori=0toUBound(arrFolder)

FolderPath=arrFolder(i)

IfFso.folderexists(Server.MapPath(FolderPath))then

Fso.deleteFolderServer.MapPath(FolderPath)

IfErrthen

ShowError"

删除目录失败"

"

else

DelFolder=true

IsExistFile(FilePath)

判断文件或目录是否存在

FunctionIsExistFile(FilePath)

IsExistFile=false

IsExistFile=True

IfFso.folderexists(Server.MapPath(FilePath))then

判断文件或目录是否存在失败"

IsExistFile=true

删除文件或目录

Fso.deleteFolderServer.MapPath(FilePath)

删除文件或目录失败"

ReNameFile((oldName,newName)

重命名文件或目录

strOldName'

原文件名多个用"

strNewName'

新文件名多个用"

隔开

上面两个参数请保持一致

FunctionReNameFile(strOldName,strNewName)

Dimfso,arrOld,arrNew,i,oldName,newName

old=GetSafeStr(strOldName,"

Newfile=GetSafeStr(strNewName,"

Ifold="

orNewfile="

ReNameFile=false

arrOld=Split(strOldName,"

arrNew=Split(strNewName,"

IfUBound(arrOld)<

UBound(arrNew)then

fori=0toUBound(arrOld)

oldName=Server.MapPath(arrOld(i))

newName=Server.MapPath(arrNew(i))

IfFso.FileExists(oldName)andnotFso.FileExists(newName

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 中考

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1