asp操作文件的函数

   日期:2017-06-15

' 删除指定的文件
Sub DoDelFile(sPathFile)
 On Error Resume Next
 Dim oFSO
 Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
 oFSO.DeleteFile(Server.MapPath(sPathFile))
 Set oFSO = Nothing

End Sub


'利用FSO直接读取模板
function fsow(filename)
set mfo=Server.CreateObject("Scripting.FileSystemObject")
set rtf=mfo.OpenTextFile(server.mappath(filename),1)
body=rtf.readall
fsow=body
end function

'创建文件
sub creatfile(filePath,nr)
 Set fs=Server.CreateObject("Scripting.FileSystemObject")
 on error resume next  
  Set fout = fs.CreateTextFile(filePath,true) 
  fout.WriteLine nr 
  fout.close 
 set fs=nothing
end sub

'生成文件夹
function CreateFolder(Folder)
 Dim Fso, F
 Set Fso = Server.CreateObject("Scripting.FileSystemObject")
 If Fso.FolderExists(Server.MapPath(Folder)) Then Exit function
 Set F = Fso.CreateFolder(Server.MapPath(Folder))
 Set F = Nothing
 Set Fso = Nothing
        CreateFolder=Folder
End function

'删除文件目录
<%
set objfilesys=server.createobject("scripting.filesystemobject")
ss=server.mappath("zy/"+membername)
'response.write objfilesys.FolderExists(ss)
if objfilesys.FolderExists(ss) then
objfilesys.DeleteFolder(ss)
end if
Set objfilesys = Nothing 

'判断目录是否存在
if fso.FolderExists(userdir &"/" & username) then
response.redirect("error.asp?error=userfolder")
response.end
end if