回 帖 发 新 帖 刷新版面

主题:删除文件

我想用ASP来删除我指定文件夹里面的一个文件怎么写实现?请高手指教一下.先谢谢了.

回复列表 (共3个回复)

沙发

set f=server.createobject("scripting.filesystemobject")
f.deletefile "c:\1.txt"
这样就删除了c盘根目录下的文件1.txt文件

板凳

删除文件前判断文件是否存在
或之前加上
On Error Resume Next
加强程序"强壮性",避免Runtime err

3 楼

提供给你来个函数,可以重复调用哦
先判断文件是否存在,在进行删除!
函数代码如下:
'-----------------------------------
'函数功能:检查某一文件是否存在
'----------------------------------
Function CheckFile(FilePath) 
    Dim fso
    Filepath=Server.MapPath(FilePath)
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(FilePath) then
    '存在
        CheckFile = True
    Else
    '不存在
        CheckFile = False
    End if
    Set fso = nothing
End Function
'--------------
'函数功能:删除文件
'--------------
function delfile(filepathX)
    dim path,fs
    path=server.MapPath(trim(filepathX))
    SET fs=server.CreateObject("Scripting.FileSystemObject")
    if FS.FileExists(path) then
        FS.DeleteFile(path) 
    end if 
    set fs=nothing
end function

我来回复

您尚未登录,请登录后再回复。点此登录或注册