常用的asp文件与文件夹操作函数
下面是我收集了大家在开发中常用的asp教程文件与文件夹操作函数,有文件创建,删除以及文件夹删除,创建等功能。
<%
'文件操作函数:写文件
private sub writefile(filename,text)
dim fso,file
set fso = createobject("scripting.filesystemobject")
set file = fso.createtextfile(filename, true)
file.write(text)
file.close
set file = nothing
set fso = nothing
end sub'文件操作函数:读文件
function readfile(filename)
dim fso,file
set fso = createobject("scripting.filesystemobject")
set file = fso.opentextfile(filename, 1)
readfile = file.readall()
file.close
set file = nothing
set fso = nothing
end function'测试文件夹是否存在
function checkfolder(folder)
dim fso,exists
set fso = createobject("scripting.filesystemobject")
checkfolder = fso.folderexists(folder)
set fso = nothing
end function'创建文件夹
private sub createfolder(folder)
dim fso
set fso = createobject("scripting.filesystemobject")
fso.createfolder(folder)
set fso = nothing
end sub'删除文件夹
private sub deletefolder(folder)
dim fso
set fso = createobject("scripting.filesystemobject")
fso.deletefolder(server.mappath(folder))
set fso = nothing
end sub'删除文件
private sub deletefile(fname)
set fso = createobject("scripting.filesystemobject")
if fso.fileexists(server.mappath(fname)) then
set f = fso.getfile(server.mappath(fname))
f.delete()
set f = nothing
end if
set fso = nothing
end sub'测试文件夹是否存在,不存在则建立
private sub checksavepath(filesavepath)
p_tmp = split(filesavepath,"/")
path = ""
for i = 0 to ubound(p_tmp)
if p_tmp(i) = "" then
path = path & "/"
else
path = path & p_tmp(i) & "/"
if not checkfolder(server.mappath(path)) then call createfolder(server.mappath(path))
end if
next
end sub
%>
补充:asp教程,高级应用