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/