我设法写了这个,但它没有工作
<%@ 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 run-time di Microsoft VBScript error&#39; 800a004c&#39; Impossibile trovare il percorso /index.asp,riga 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 :(得分: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