Google chrome 定位;chrome.exe“;
我有一个调用Chrome的宏,但是在不同的机器上部署这段代码会因为Chrome在每台机器上的完整文件路径不同而受到影响。为了缓解这种情况,我想对“chrome.exe”执行一次性搜索,并将文件路径存储为变量。下面的方法似乎有效,但是递归性会产生堆栈空间问题(运行时错误28) 这似乎是一个如此简单的操作,递归搜索遍布所有常见的论坛,但我不能得到它的权利Google chrome 定位;chrome.exe“;,google-chrome,file-search,Google Chrome,File Search,我有一个调用Chrome的宏,但是在不同的机器上部署这段代码会因为Chrome在每台机器上的完整文件路径不同而受到影响。为了缓解这种情况,我想对“chrome.exe”执行一次性搜索,并将文件路径存储为变量。下面的方法似乎有效,但是递归性会产生堆栈空间问题(运行时错误28) 这似乎是一个如此简单的操作,递归搜索遍布所有常见的论坛,但我不能得到它的权利 Function Recurse(sPath As String) As String Dim FSO As New FileSystemObje
Function Recurse(sPath As String) As String
Dim FSO As New FileSystemObject
Dim myFolder As Folder
Dim mySubFolder As Folder
Dim myFile As File
Application.ScreenUpdating = False
Set myFolder = FSO.GetFolder("C:\")
For Each mySubFolder In myFolder.SubFolders
For Each myFile In mySubFolder.Files
If myFile.Name = "chrome.exe" Then
Debug.Print myFile.Name & " in " & myFile.Path
Exit For
End If
Next
Recurse = Recurse(mySubFolder.Path)
Next
Application.ScreenUpdating = True
End Function
Sub ChromeSearch()
Call Recurse("C:\")
End Sub
注意,您正在将参数
sPath
传递给递归函数
然后,您将忽略此参数,并在每次调用时搜索文件夹C:\
。现在您有了一个没有终止条件的递归函数,因此当然会得到一个堆栈溢出异常
简单地替换
Set myFolder = FSO.GetFolder("C:\")
与
并替换:
Recurse = Recurse(mySubFolder.Path)
与
(或以这种语言连接文件夹的方式)
关于查找Chrome.exe的主题,如果您首先在两个地方查找,将节省大量时间:
- “C:\ProgramFiles(x86)\Google\Chrome\Application\Chrome.exe”
- (环境变量LOCALAPPDATA)+ “\Google\Chrome\Application\Chrome.exe”
which
命令,但随后我看到C:///code>…刚刚搜索并找到了一个感谢@AndrewShepherd。建议的更改FSO.GetFolder(sPath)返回“未找到路径”错误。@JonPotter-必须将子路径连接到基本路径。我为您添加了一行额外的代码。(你可能需要稍微修改一下——我甚至不知道你用的是哪种语言:-)非常感谢你的帮助,尽管我的学童犯了错误。它是Excel VBA,我在大多数情况下都相当熟练,但是多年来都没有接触过VBA,而这一个正好在我的皮肤下:|
Recurse = Recurse(mySubFolder.Path)
Recurse = Recurse(sPath + "\\" + mySubFolder.Path);