是否可以删除文件夹的所有内容?



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

<%@ 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 '800a004c' Impossibile trovare il percorso/索引.asp, 里加 37

这意味着:

运行时错误...找不到路径...索引.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>

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

相关内容

  • 没有找到相关文章

最新更新