fs.DeleteFile(VAR)不删除文件 [英] fs.DeleteFile(var) not deleting file

查看:865
本文介绍了fs.DeleteFile(VAR)不删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一些我们的网站,我们正在运行节省了MSSQL数据库在该目录中一个.bak文件的备份脚本。

我们每天跑一个Git风格备份,以便我们必须到现场进行任何更改。由于备份时间差异,我们真的不希望删除今天的备份,还是昨天的,所以我们会删除3天过去。

下面的.asp页,如果的DeleteFile(30行)被注释掉运行正常。如果文件存在它遵循正确的分支,所以可以看到该文件,但如果删除行注释掉它打破了。

 <%@ LANGUAGE =VBSCRIPTcodePAGE =65001%>
!< D​​OCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
< HEAD>
    < META HTTP-EQUIV =Content-Type的CONTENT =text / html的;字符集= UTF-8/>
    <标题>吹扫 - LT; /标题>
< /头>
<身体GT;
    <%
        瓦尔INIT
        朦胧月,日,年,迪尔,文件,Absolutepath,期间,FS
        组FS =的Server.CreateObject(Scripting.FileSystemObject的)        删除设置备份的日期三天前
        期间= DATEADD(D,-3,日期)
        月=日期部分(M,周期)
        天=日期部分(D,周期)
        年= DATEPART(YYYY,周期)        位置设置
        DIR =使用Server.Mappath(。)及\\
        文件=dbBackup-&放大器;本月&安培; - 与&天&功放; - 与&新年&安培; _1.bak
        Absolutepath = DIR功放&;文件        实际尝试删除
        如果fs.FileExists(Absolutepath)然后
            fs.DeleteFile(Absolutepath)
            的Response.Write(&安培;#34;&放大器;档案与&放大器;#34;删除< BR />中)
        其他
            的Response.Write(404:放大器;#34;&放大器;档案与&放大器;#34;&失踪LT; BR />中)
        万一
    %GT;
    执行完毕。
< /身体GT;
< / HTML>

我曾尝试

 'fs.DeleteFile(Absolutepath)

 'fs.DeleteFile Absolutepath

 'fs.DeleteFile(文件)

 'fs.DeleteFile文件

要无济于事。任何想法?

编辑:

本地服务器说500 =

 微软VBScript编译错误800a0414调用子时不能使用圆括号/test/index.asp 23行fs.CreateTextFile(Absolutepath,真)


解决方案

答案最后被认为fs.DeleteFile不带括号

  fs.DeleteFile(Absolutepath)

结束了

  fs.DeleteFile Absolutepath

On a few of our sites we are running a backup script that saves a MSSQL database as a .bak file in a that directory.

Every day we run a Git style backup so that we have any changes to the site. Due to variance in backup timing We don't really want to delete today's backup, or yesterday's, so we will delete 3 days past.

The following .asp page runs fine if the DeleteFile(line 30) is commented out. if the file exists it follows the correct branch, so it can see the file, but if the delete line is uncommented it breaks.

<%@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("&#34;" & File & "&#34; deleted <br/>") 
        Else
            Response.Write("404: &#34;" & File & "&#34; missing <br/>") 
        End If
    %>
    Execution complete.
</body>
</html>

I have tried

'fs.DeleteFile(Absolutepath)

and

'fs.DeleteFile Absolutepath

and

'fs.DeleteFile(File)

and

'fs.DeleteFile File

To no avail. any ideas?

edit:

local server says 500 =

Microsoft VBScript compilation error '800a0414' 

Cannot use parentheses when calling a Sub 

/test/index.asp, line 23 

fs.CreateTextFile(Absolutepath,True)

解决方案

The Answer ended up being that fs.DeleteFile does not take parenthesis

fs.DeleteFile(Absolutepath)

ended up being

fs.DeleteFile Absolutepath

这篇关于fs.DeleteFile(VAR)不删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆