【问题标题】:Is it possible to delete all content of a folder?是否可以删除文件夹的所有内容?
【发布时间】:2018-01-05 16:35:36
【问题描述】:

我设法写了这个,但它不起作用

<%@ Language="VBScript" %>
<!DOCTYPE html>
<html>
<body>
<%

    'Delete All Subfolders and Files in a Folder And deletes itself

    Function discardScript()
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        strScript = Wscript.ScriptFullName
        objFSO.DeleteFile(strScript)
    End Function

    Dim folderName
    Dim x
    Dim currentPath
    Const DeleteReadOnly = TRUE
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    folderName = Request.QueryString("folderName")

    A = Request.ServerVariables("PATH_INFO")
    response.write("PATH_INFO A: "&A&"<br />")
    B = split(A,"/")
    For x = LBound(B) to UBound(B)
        response.write("PATH_INFO B["&x&"]: "&B(x)&"<br />")
    Next
    C = B(ubound(B)-1)&"/"
    response.write("PATH_INFO C: "&C&"<br />")
    if (folderName <> "") then
        currentPath = C&folderName&"/*"
        response.write("Deleting '"&folderName&"'...<br />")
        if objFSO.FileExists(currentPath) then
            objFSO.DeleteFile(currentPath), DeleteReadOnly
        end if

        objFSO.DeleteFolder(currentPath),DeleteReadOnly
    else
        response.write("No folder specified")
    end if

    'objFSO.DeleteFile("C:\FSO\*"), DeleteReadOnly
    'objFSO.DeleteFolder("C:\FSO\*"),DeleteReadOnly

%>
</body>
</html>

Errore di 运行时 di Microsoft VBScript 错误 '800a004c' 不可能的 trovare il percorso /index.asp, 里加 37

这意味着:

运行时错误...找不到路径...index.asp 第 37 行

有什么想法吗?

编辑

感谢@schudel 和一些研究我得到了这个,希望它有用

<%@ Language="VBScript" %>
<!DOCTYPE html>
<html>
<body>
<%

    'Delete All Subfolders and Files in a Folder And deletes itself

    Function discardScript()
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        strScript = Wscript.ScriptFullName
        objFSO.DeleteFile(strScript)
    End Function

    Dim folderName
    Dim deleteScript
    Dim x
    Dim fullPath
    Const DeleteReadOnly = TRUE
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    folderName = Request.QueryString("folderName")

    BASE = Request.ServerVariables("APPL_PHYSICAL_PATH")

    response.write("APPL_PHYSICAL_PATH = "&BASE&"<br />")

    if (folderName <> "") then
        'DELETE VARIABLES
        fullPath = BASE&folderName&"\"
        Set objFS = CreateObject("Scripting.FileSystemObject")

        if (objFS.FolderExists(fullPath)) then
            Set objFolder = objFS.GetFolder(fullPath) 
            Set objFiles = objFolder.Files
            dim curFile
        else
            response.write("Folder '"&folderName&"' does not exists!")
            response.End
        end if
        'DELETE PROCESS
        response.write("Deleting content from '"&fullPath&"' ...<br />")
        For each curFile in objFiles
            response.write("Deleting <strong>FILE</strong>: '"&curFile&"' ...")
            objFS.DeleteFile(curFile), DeleteReadOnly
        Next
        response.write("Deleting <strong>FOLDER</strong>: '"&objFolder&"' ...")
        objFS.DeleteFolder(objFolder), DeleteReadOnly
    else
        response.write("No folder specified")
    end if

    if (deleteScript = "YES") then
        discardScript()
    end if

%>
</body>
</html>

【问题讨论】:

  • 如果您使用的是在 ASP.NET 上运行的 Web 窗体,为什么要说“经典 ASP”并将其标记为 asp-classic,这与经典 ASP 完全不同?
  • 因为我需要在 Classic ASP 上执行此操作
  • 如果你需要在Classic ASP上做,你为什么把它标记为ASP.NET并显示.NET代码?
  • 因为我不知道这一切的区别...
  • 你需要弄清楚你到底在使用什么。文件是否以 .aspx 或 asp 结尾?

标签: asp-classic windows-server-2008


【解决方案1】:

GetFolder 将返回一个文件夹对象,其中包含一个文件和一个子文件夹集合。 请参阅https://msdn.microsoft.com/en-us/library/aa262405(v=vs.60).aspx 了解更多信息。

  Set objFS = CreateObject("Scripting.FileSystemObject")
  Set objFolder = objFS.GetFolder("c:\myFolder\") 
  Set objFiles = objFolder.Files
  dim curFile

  For each curFile in objFiles
    objFS.DeleteFile(curFile)
  Next

【讨论】:

  • 以后发帖的提示:在代码块前添加&lt;!-- language: lang-vbs --&gt; 将使其美化为VBS代码。 :)
  • 现在试试这个!
猜你喜欢
  • 1970-01-01
  • 2014-06-15
  • 1970-01-01
  • 2022-01-23
  • 2014-04-01
  • 2012-09-19
  • 1970-01-01
  • 2011-05-16
  • 1970-01-01
相关资源
最近更新 更多