2017-07-29 141 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

現在就試試這個! –

相關問題