FSO(fileSystemObject)判断文件及文件夹是否存在(ASP源码)

so中判断文件夹是否存在


set fso = server.createobject("scripting.filesystemobject")
if fso.FolderExists(server.mappath("../folderName"))=false then
REsponse.write("此文件夹不存在")
end if
fso中判断文件是否存在
set fso = server.createobject("scripting.filesystemobject")
if fso.fileexists(server.mappath("../folderName/fileName.htm")) = true then
Response.write("文件存在")
end if

fso中写文件
dim fileName,fileContent
fileName = replace(date(),"-","")
randomize
fileName = fileName & cstr(int(rnd(10)*100000)) & ".htm"
HtmlName = fileName 'HtmlName为数据库中的文件名
set fso = server.CreateObject("scripting.filesystemobject")
if fso.FolderExists(server.MapPath("./Files"))=false then '检查要生成的HTML文件夹是否存在
fso.CreateFolder(server.MapPath("../Files"))
end if
fileName = server.MapPath("../Files") & "/" & fileName
set MyFile = fso.opentextfile(fileName,2,true)
fileContent = "....(content)"
MyFile.write(fileContent)
MyFile.Close()
set MyFile = nothing
fso中删除文件
set fso = server.createobject("script.filesystemobject")
fileName = ..
fso.deletefile(fileName)
set fso = nothing

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>