VBScript是否具有在文件资源管理器中获取当前所选文件的路径的功能?如果是这样,功能是什么?我正在寻找像
这样的东西Set fileObj = CreateObject("Scripting.FileSystemObject")
dim filepath
filepath = fileObj.GetCurrentSelection() 'doesn´t exist
dim result
result = filepath 'communicate with LiveCode
答案 0 :(得分:4)
我写了一个简单的例子
请记住,可能有多个打开的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
答案 1 :(得分:0)
通过此尝试,您可以获得当前所选文件的路径。您还需要
Set objFS=CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFile= objArgs(0)
Set objFile = objFS.OpenTextFile(strFile)
Set objFile = objFS.GetFile(strFile)
WScript.Echo objFile.Path