topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Sunday December 15, 2024, 4:03 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: VBS: Select one file in a folder  (Read 4809 times)

Yaron

  • Participant
  • Joined in 2014
  • *
  • default avatar
  • Posts: 22
    • View Profile
    • Donate to Member
VBS: Select one file in a folder
« on: July 18, 2017, 10:48 AM »
Hello,

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.

Yaron

  • Participant
  • Joined in 2014
  • *
  • default avatar
  • Posts: 22
    • View Profile
    • Donate to Member
Re: VBS: Select one file in a folder
« Reply #1 on: July 18, 2017, 06:11 PM »