vbscript - 如何获取当前选定文件的路径

标签 vbscript selection explorer livecode

VBScript 是否有获取文件资源管理器中当前选定文件路径的函数?如果有,作用是什么?我正在寻找类似的东西

Set fileObj = CreateObject("Scripting.FileSystemObject")
dim filepath 
filepath = fileObj.GetCurrentSelection() 'doesn´t exist
dim result
result = filepath 'communicate with LiveCode

最佳答案

我写了一个简单的例子。
请记住,可能有多个打开的 Windows 资源管理器窗口,这将列出所有窗口。

Function GetSelectedFiles() 'Returns paths as array of strings
    Dim FileList, Window, SelectedItem
    'avoid duplicates by storing paths in dictionary keys
    Set FileList = CreateObject("Scripting.Dictionary")

    With CreateObject("Shell.Application")
        For Each Window In .Windows
            'skip IE Windows
            If InStr(1, Window.FullName, "iexplore.exe", vbTextCompare) = 0 Then
                For Each SelectedItem In Window.Document.SelectedItems
                    FileList(SelectedItem.Path) = Null
                Next
            End If
        Next
    End With

    GetSelectedFiles = FileList.Keys 'array of paths
End Function

MsgBox  "Click OK after selecting the items",  _
        vbOKOnly Or vbInformation, "Select a few items"

Dim SelectedFiles
    SelectedFiles =  GetSelectedFiles

MsgBox  "You selected: " & vbNewLine  & vbNewLine & _
         Join(SelectedFiles, vbNewLine), vbOKOnly Or vbInformation, "Selected Items"

'loop through array
'Dim FileItem
'For Each FileItem In SelectedFiles
'   WScript.Echo FileItem
'Next

关于vbscript - 如何获取当前选定文件的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20326651/

相关文章:

javascript - 关闭浏览器标签的脚本

c++ - nth_element 是如何实现的?

javascript - 如何从 Highstock 图表中获取导航器选择?

windows - 以编程方式打开 Windows 7 "Map Network Drive"对话框

command-line - 通过 VBS 带参数运行命令行

c - 选择排序逻辑错误

Python:程序在资源管理器中打开不正确的文件路径?

.net - 使用多个文件作为资源管理器的参数打开程序一次

Javascript IE 事件,这个

vbscript - 在vbs中发送Windows键?