2017-07-29 102 views
0

我设法写这篇文章,但它不工作是否可以删除文件夹的所有内容?

<%@ 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迪运行时迪微软的VBScript错误 '800a004c' Impossibile 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> 
+0

如果您使用的Web窗体运行于ASP.NET上,那么您为什么说“经典ASP”并将其标记为“asp-classic”?它与传统ASP完全不同? – mason

+0

因为我需要在经典ASP上做到这一点 –

+0

如果你需要在经典ASP上做到这一点,为什么你把它标记为ASP.NET并显示.NET代码? – mason

回答

2

的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 
+1

对未来文章的提示:在代码块之前添加'<! - language:lang-vbs - >'将使它成为VBS代码。 :) –

+0

现在就试试这个! –

相关问题