asp结合fso实现文件或文件夹创建删除等操作的函数
程序员文章站
2022-03-25 21:01:02
'////////////////////////////////////////////////fso操作////////////////////////////////...
'////////////////////////////////////////////////fso操作/////////////////////////////////////
'判断文件夹是否存在
function folderexits(folder)
folder=server.mappath(folder)
set fso= server.createobject("scripting.filesystemobject")
if fso.folderexists(folder) then
folderexits=true
else
folderexits=false
end if
end function
'判断文件是否存在
function fileexits(filename)
filename=server.mappath(filename)
set fso= server.createobject("scripting.filesystemobject")
if fso.fileexists(filename) then
fileexits=true
else
fileexits=false
end if
end function
'创建文件夹
function createfolder(folder)
on error resume next
folder=server.mappath(folder)
set fso = server.createobject("scripting.filesystemobject")
fso.createfolder(folder)
if err>0 then
err.clear
createfolder=false
else
createfolder=true
end if
end function
'创建文件
function createfile(filename,content)
on error resume next
filename=server.mappath(filename)
set fso = server.createobject("scripting.filesystemobject")
set fd=fso.createtextfile(filename,true)
fd.writeline content
if err>0 then
err.clear
createfile=false
else
createfile=true
end if
end function
'删除文件
function deletefile(filename)
on error resume next
set fso = server.createobject("scripting.filesystemobject")
if fso.fileexists(filename) then
fso.deletefile filename,true
end if
if err>0 then
err.clear
deletefile=false
else
deletefile=true
end if
end function
'删除文件夹
function deletefolder(folder)
on error resume next
folder=server.mappath(folder)
set fso = server.createobject("scripting.filesystemobject")
if fso.folderexists(folder) then
fso.deletefolder folder,true
end if
if err>0 then
err.clear
deletefolder=false
else
deletefolder=true
end if
end function
'判断文件夹是否存在
function folderexits(folder)
folder=server.mappath(folder)
set fso= server.createobject("scripting.filesystemobject")
if fso.folderexists(folder) then
folderexits=true
else
folderexits=false
end if
end function
'判断文件是否存在
function fileexits(filename)
filename=server.mappath(filename)
set fso= server.createobject("scripting.filesystemobject")
if fso.fileexists(filename) then
fileexits=true
else
fileexits=false
end if
end function
'创建文件夹
function createfolder(folder)
on error resume next
folder=server.mappath(folder)
set fso = server.createobject("scripting.filesystemobject")
fso.createfolder(folder)
if err>0 then
err.clear
createfolder=false
else
createfolder=true
end if
end function
'创建文件
function createfile(filename,content)
on error resume next
filename=server.mappath(filename)
set fso = server.createobject("scripting.filesystemobject")
set fd=fso.createtextfile(filename,true)
fd.writeline content
if err>0 then
err.clear
createfile=false
else
createfile=true
end if
end function
'删除文件
function deletefile(filename)
on error resume next
set fso = server.createobject("scripting.filesystemobject")
if fso.fileexists(filename) then
fso.deletefile filename,true
end if
if err>0 then
err.clear
deletefile=false
else
deletefile=true
end if
end function
'删除文件夹
function deletefolder(folder)
on error resume next
folder=server.mappath(folder)
set fso = server.createobject("scripting.filesystemobject")
if fso.folderexists(folder) then
fso.deletefolder folder,true
end if
if err>0 then
err.clear
deletefolder=false
else
deletefolder=true
end if
end function
上一篇: AJAX简单应用实例-弹出层