ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

VBS: Select one file in a folder



The following code selects arg1 in a Windows Explorer folder:

--- ---Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("""" & WScript.Arguments(0) & """")
WScript.Sleep 400

' objShell.SendKeys("^a{F5}") ' Deslect All.

Set objShellAPP = CreateObject("Shell.Application")
On Error Resume Next ' For new unsaved files.
With objShellAPP.Windows(objShellAPP.Windows.Count - 1).document
.SelectItem .Folder.Items.Item(WScript.Arguments(1)), 17
End With

Set objShell = Nothing
Set objShellAPP = Nothing
If fileA is already selected in the folder and fileB is passed as arg1, both files are selected.

How can I have fileA deselected and only fileB selected?
The commented line
--- ---objShell.SendKeys("^a{F5}") is a workaround, but there must be a better way.

Thank you.



[0] Message Index

Go to full version