如何获取当前所选文件的路径 [英] How do I get the path to the currently selected file

查看:118
本文介绍了如何获取当前所选文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VBScript是否具有在文件资源管理器中获取当前所选文件的路径的功能?如果是这样,功能是什么?我正在寻找类似的东西

Does VBScript have a function to get the path to the currently selected file in File Explorer? If so, what is the function? I'm looking for something like

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

推荐答案

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

I wrote a simple example.
Keep in mind there may be more than one open windows explorer window and this will list them all.

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

这篇关于如何获取当前所选文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆