asp结合fso实现文件或文件夹创建删除等操作的函数

2018-09-06 11:22

阅读:447

  ////////////////////////////////////////////////FSO操作/////////////////////////////////////
判断文件夹是否存在
FunctionFolderExits(Folder)
Folder=Server.Mappath(Folder)
SetFSO=Server.CreateObject(Scripting.FileSystemObject)
IFFSO.FolderExists(Folder)Then
FolderExits=true
Else
FolderExits=false
EndIF
EndFunction

判断文件是否存在
FunctionFileExits(FileName)
FileName=Server.Mappath(FileName)
SetFSO=Server.CreateObject(Scripting.FileSystemObject)
IFFSO.FileExists(FileName)Then
FileExits=true
Else
FileExits=false
EndIF
EndFunction

创建文件夹
FunctionCreateFolder(Folder)
onerrorresumenext
Folder=Server.Mappath(Folder)
SetFSO=Server.CreateObject(Scripting.FileSystemObject)
FSO.CreateFolder(Folder)
iferr>0then
err.clear
CreateFolder=False
else
CreateFolder=True
endif
Endfunction

创建文件
FunctionCreateFile(FileName,Content)
onerrorresumenext
FileName=Server.Mappath(FileName)
SetFSO=Server.CreateObject(Scripting.FileSystemObject)
setfd=FSO.createtextfile(FileName,true)
fd.writelineContent
iferr>0then
err.clear
CreateFile=False
else
CreateFile=True
endif
Endfunction

删除文件
functionDeleteFile(FileName)
onerrorresumenext
SetFSO=Server.CreateObject(Scripting.FileSystemObject)
ifFSO.FileExists(FileName)then
FSO.DeleteFileFileName,true
endif
iferr>0then
err.clear
DeleteFile=False
else
DeleteFile=True
endif
endfunction

删除文件夹
functionDeleteFolder(Folder)
onerrorresumenext
Folder=server.MapPath(Folder)
SetFSO=Server.CreateObject(Scripting.FileSystemObject)
ifFSO.FolderExists(Folder)then
FSO.DeletefolderFolder,true
endif
iferr>0then
err.clear
Deletefolder=False
else
Deletefolder=True
endif
endfunction


评论


亲,登录后才可以留言!