【发布时间】:2015-08-17 21:25:51
【问题描述】:
我正在构建一个脚本,它会在 office 安装目录中搜索 2 个 *.dot 文件(1.dot 和 2.dot),如果找到它们就会删除它们。
我将如何管理它?它必须在 VBScript 中
注意:我已经让它搜索已安装的 Office 版本,它返回基本安装路径(IE:C:\Program Files\Microsoft Office %Version%)所以我需要它从那里搜索文件.
这是我目前用来查找这些文件的内容(但没有运气 - 它返回所有 *.dot 文件)
dim sFilename
Dim objDict
Set objDict=CreateObject("Scripting.Dictionary")
sFilename = ""
fileLocation=Session.Property("OFFICEPATH") 'this is a stored path from InstallShield = C:\Program Files\Microsoft Office %Version%\
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Call Recurse(fileLocation)
ItemArray = objDict.Items
For i = 0 To objDict.count -1
sFilename = sFilename & ItemArray(i) & VBCRLF
Next
msgbox(sFilename)
'find a specific file by name and return path
if objDict.Exists("1.dot") then
msgbox(objDict.Item("1.dot"))
end if
'find a specific file by name and return path
if objDict.Exists("2.dot") then
msgbox(objDict.Item("2.dot"))
end if
Sub Recurse(strFolderPath)
Dim objFolder
Set objFolder = objFSO.GetFolder(strFolderPath)
Dim objFile
Dim objSubFolder
For Each objFile In objFolder.Files
If (InStr(objFile.Name, ".") > 0) Then
If (LCase(Mid(objFile.Name, InStrRev(objFile.Name, "."))) = ".dot") Then
if objDict.Exists(objFile.Name)=false then
objDict.Add objFile.Name,objfile.Path
End if
End if
End If
Next
For Each objSubFolder In objFolder.SubFolders
Call Recurse(objSubFolder.Path)
Next
End Sub
【问题讨论】:
-
分享你到目前为止所拥有的东西
-
您是说您的第二个和第三个消息框没有显示
1.dot和2.dot的路径吗? -
正确(我还没有添加删除功能 - 想确保路径正确,但是是的,它们不显示路径)
-
它们是否出现在第一个消息框中?如果您通过 Windows 资源管理器导航到文件夹,您能看到
.dot文件吗? -
是的,它们显示在第一个消息框中,但不是第二个或第三个,是的,这些文件存在!
标签: vbscript