首先,我不是编写VBScripts的专家。
我要求删除文件&远程系统的文件夹只需单击一下。我试图在VBScript下面构建,但不知怎的,它不起作用。我请求您的任何帮助以更正相同或使用新脚本来帮助我满足要求。非常感谢在这方面的任何帮助,在此先感谢。
以下内容: C:\ Test - 是我要删除文件和目录的目录。子文件夹 C:\ computerList.txt - 是包含所有远程系统IP地址的文本文件。
Const strPath = "C:\Test"
Set computerList = objfso.OpenTextFile ("C:\computerList.txt", 1)
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Call Search (strPath)
WScript.Echo"Done."
Sub Search(str)
Do While Not computerList.AtEndOfStream
strComputer = computerList.ReadLine
Dim objFolder, objSubFolder, objFile
Set objFolder = objFSO.GetFolder("\\" & strComputer & "\" & str)
For Each objFile In objFolder.Files
If objFile.DateLastModified < (Now() - 0) Then
objFile.Delete(True)
End If
Next
For Each objSubFolder In objFolder.SubFolders
Search(objSubFolder.Path)
' Files have been deleted, now see if
' the folder is empty.
If (objSubFolder.Files.Count = 0) Then
objSubFolder.Delete True
End If
Next
loop
End Sub
此致 Balaram Reddy
答案 0 :(得分:2)
您的第一个问题是订单行不正确:
Set computerList = objfso.OpenTextFile ("C:\computerList.txt", 1)
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
应该是
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set computerList = objfso.OpenTextFile ("C:\computerList.txt", 1)
您在宣布之前使用objfso
答案 1 :(得分:1)
使用UNC路径时,您需要使用文件夹的远程共享名称。如果您对远程PC具有管理员权限,请使用:
Const strPath = "c$\Test"