fs.DeleteFile(var) 没有删除文件
fs.DeleteFile(var) not deleting file
在我们的一些站点上,我们正在 运行 备份脚本,将 MSSQL 数据库保存为该目录中的 .bak 文件。
我们每天 运行 进行 Git 样式备份,以便我们对站点进行任何更改。由于备份时间的差异我们真的不想删除今天或昨天的备份,所以我们将删除过去 3 天的备份。
如果 DeleteFile(第 30 行)被注释掉,下面的 .asp 页面 运行 没问题。如果文件存在,它会跟随正确的分支,因此它可以看到该文件,但如果删除行未被注释,它就会中断。
<%@LANGUAGE="VBScript" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Purge</title>
</head>
<body>
<%
'Var init
dim Month, Day, Year, Dir, File, Absolutepath, Period, fs
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'setting date of backup for deletion to three days ago
Period = dateadd("D", -3, Date)
Month = datepart("M", Period)
Day = datepart("D", Period)
Year = datepart("YYYY", Period)
'location setting
Dir = Server.MapPath(".") & "\"
File= "dbBackup-" & Month & "-" & Day & "-" & Year & "_1.bak"
Absolutepath = Dir & File
'Actual attempt to delete
If fs.FileExists(Absolutepath) Then
fs.DeleteFile(Absolutepath)
Response.Write(""" & File & "" deleted <br/>")
Else
Response.Write("404: "" & File & "" missing <br/>")
End If
%>
Execution complete.
</body>
</html>
我试过了
'fs.DeleteFile(Absolutepath)
和
'fs.DeleteFile Absolutepath
和
'fs.DeleteFile(File)
和
'fs.DeleteFile File
无济于事。有什么想法吗?
编辑:
本地服务器说 500 =
Microsoft VBScript compilation error '800a0414'
Cannot use parentheses when calling a Sub
/test/index.asp, line 23
fs.CreateTextFile(Absolutepath,True)
最后的答案是 fs.DeleteFile 不带括号
fs.DeleteFile(Absolutepath)
最终成为
fs.DeleteFile Absolutepath
在我们的一些站点上,我们正在 运行 备份脚本,将 MSSQL 数据库保存为该目录中的 .bak 文件。
我们每天 运行 进行 Git 样式备份,以便我们对站点进行任何更改。由于备份时间的差异我们真的不想删除今天或昨天的备份,所以我们将删除过去 3 天的备份。
如果 DeleteFile(第 30 行)被注释掉,下面的 .asp 页面 运行 没问题。如果文件存在,它会跟随正确的分支,因此它可以看到该文件,但如果删除行未被注释,它就会中断。
<%@LANGUAGE="VBScript" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Purge</title>
</head>
<body>
<%
'Var init
dim Month, Day, Year, Dir, File, Absolutepath, Period, fs
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'setting date of backup for deletion to three days ago
Period = dateadd("D", -3, Date)
Month = datepart("M", Period)
Day = datepart("D", Period)
Year = datepart("YYYY", Period)
'location setting
Dir = Server.MapPath(".") & "\"
File= "dbBackup-" & Month & "-" & Day & "-" & Year & "_1.bak"
Absolutepath = Dir & File
'Actual attempt to delete
If fs.FileExists(Absolutepath) Then
fs.DeleteFile(Absolutepath)
Response.Write(""" & File & "" deleted <br/>")
Else
Response.Write("404: "" & File & "" missing <br/>")
End If
%>
Execution complete.
</body>
</html>
我试过了
'fs.DeleteFile(Absolutepath)
和
'fs.DeleteFile Absolutepath
和
'fs.DeleteFile(File)
和
'fs.DeleteFile File
无济于事。有什么想法吗?
编辑:
本地服务器说 500 =
Microsoft VBScript compilation error '800a0414'
Cannot use parentheses when calling a Sub
/test/index.asp, line 23
fs.CreateTextFile(Absolutepath,True)
最后的答案是 fs.DeleteFile 不带括号
fs.DeleteFile(Absolutepath)
最终成为
fs.DeleteFile Absolutepath