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
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
try this by this you can get the path to the currently selected file.you also need to
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
来源:https://stackoverflow.com/questions/20326651/how-do-i-get-the-path-to-the-currently-selected-file