asp下利用fso实现文件夹或文件移动改名等操作函数
asp下利用fso实现文件夹或文件移动改名等操作函数
发布时间:2016-12-29 来源:查字典编辑
摘要:asp利用fso实现文件的移动functionmovefiles(sFolder,dFolder)onerrorresumenextdimf...

asp利用fso实现文件的移动

functionmovefiles(sFolder,dFolder)

onerrorresumenext

dimfso

setfso=server.createobject("scripting.filesystemobject")

iffso.folderexists(server.mappath(sFolder))andfso.folderexists(server.mappath(dFolder))then

fso.copyfolderserver.mappath(sFolder),server.mappath(dFolder)

movefiles=true

else

movefiles=false

setfso=nothing

callalertbox("系统没有找到指定的路径["&sFolder&"]!",2)

endif

setfso=nothing

endfunction

asp修改文件夹名称

functionrenamefolder(sFolder,dFolder)

onerrorresumenext

dimfso

setfso=server.createobject("scripting.filesystemobject")

iffso.folderexists(server.mappath(sFolder))then

fso.movefolderserver.mappath(sFolder),server.mappath(dFolder)

renamefolder=true

else

renamefolder=false

setfso=nothing

callalertbox("系统没有找到指定的路径["&sFolder&"]!",2)

endif

setfso=nothing

endfunction

asp检查文件夹是否存在

functioncheckfolder(sPATH)

onerrorresumenext

dimfso

setfso=server.createobject("scripting.filesystemobject")

iffso.folderexists(server.mappath(sPATH))then

checkfolder=true

else

checkfolder=false

endif

setfso=nothing

endfunction

asp检查文件是否存在

functioncheckfile(sPATH)

onerrorresumenext

dimfso

setfso=server.createobject("scripting.filesystemobject")

iffso.fileexists(server.mappath(sPATH))then

checkfile=true

else

checkfile=false

endif

setfso=nothing

endfunction

asp创建文件夹

functioncreatedir(sPATH)

dimfso,pathArr,i,path_Level,pathTmp,cPATH

onerrorresumenext

sPATH=replace(sPATH,"","/")

setfso=server.createobject("scripting.filesystemobject")

pathArr=split(sPATH,"/")

path_Level=ubound(pathArr)

fori=0topath_Level

ifi=0thenpathTmp=pathArr(0)&"/"elsepathTmp=pathTmp&pathArr(i)&"/"

cPATH=left(pathTmp,len(pathTmp)-1)

ifnotfso.folderexists(cPATH)thenfso.createfolder(cPATH)

next

setfso=nothing

iferr.number<>0then

err.clear

createdir=false

else

createdir=true

endif

endfunction

删除文件夹,这里是删除系统中栏目的文件夹

functiondelclassfolder(sPATH)

onerrorresumenext

dimfso

setfso=server.createobject("scripting.filesystemobject")

iffso.folderexists(server.mappath(sPATH))then

fso.deletefolder(server.mappath(sPATH))

endif

setfso=nothing

endfunction

删除新闻内容文件

functiondelnewsfile(sPATH,filename)

onerrorresumenext

dimfso,tempArr,cPATH,ePATH,i:i=0

setfso=server.createobject("scripting.filesystemobject")

sPATH=sPATH&filename&site_extname

iffso.fileexists(server.mappath(sPATH))then

fso.deletefile(server.mappath(sPATH))

while(i<>-1)

i=i+1

ePATH=replace(sPATH,filename&".",filename&"_"&i+1&".")

iffso.fileexists(server.mappath(ePATH))then

fso.deletefile(server.mappath(ePATH))

else

i=-1

endif

wend

endif

endfunction

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新ASP教程学习
热门ASP教程学习
编程开发子分类