Highlight a filename in the current directory (explorer window)
Hi
I'm looking to copy a file to the current directory open in an explorer window (I'm going to get the program to launch from the right button context menu).
I've got the file to copy over, but I need to be able to highlight/select it - the same as if the user had clicked on it.
Essentially I need a bit of code I can pass 'path/file 3.txt' to which will take me from this:
https://2.bp.blogspot.com/-gUQiGC9pQ...2Bselected.jpg
to this:
https://2.bp.blogspot.com/-UyLHc6FDS...0/selected.jpg
Something similar was done in this post, but I need to work with the current explorer window, not open a new one.
Is this possible?
Thanks for reading! :)
Re: Highlight a filename in the current directory (explorer window)
Try this...
Code:
Process.Start("explorer.exe", "/select," & "PATH_TO_FILETOSELECT")
Re: Highlight a filename in the current directory (explorer window)
Quote:
Originally Posted by
.paul.
Try this...
Code:
Process.Start("explorer.exe", "/select," & "PATH_TO_FILETOSELECT")
Doesn't that start a new explorer, which he stated he didn't want.
Quote:
Originally Posted by
Precision999
...
Something similar was done in
this post, but I need to work with the current explorer window, not open a new one.
Is this possible?
...
Re: Highlight a filename in the current directory (explorer window)
Quote:
Originally Posted by
passel
Doesn't that start a new explorer, which he stated he didn't want.
I noticed that after i posted. I had a look in spy++. Don't think that's possible that way. Doesn't classic vb have a curdir method? Is there something similar for setting the current file?
Re: Highlight a filename in the current directory (explorer window)
Might be possible with SendKeys...
Re: Highlight a filename in the current directory (explorer window)
Thanks for replies guys.
I do indeed need this to work with the current window rather then opening a new one. I'm not sure how Sendkeys would help, but from experience I'm sure that using it would bite me in the bum at some point or another!
Maybe I need to get the name of the window I'm in - but that still leaves how to 'select' the file - I've no idea how to do that.
Would a different copy method help? - maybe there's a way to do it which leaves the file selected as part of it's process?
Currently I'm just using:
Code:
mydir = Directory.GetCurrentDirectory()
My.Computer.FileSystem.CopyFile(<filename and path to copy>, mydir & "\<name of destination file>")
Re: Highlight a filename in the current directory (explorer window)
hi,
this will return what is selected in the "current" Explorer, see if this helps
the selected Files I added to a Listbox
Code:
Option Strict On
'Add Ref. COM :
'1)Microsoft Shell Controls
'2)Microsoft Shell Controls and Automation
Imports Shell32
Imports SHDocVw
Public Class Form1
Private Function GetExplorerSelectedFiles() As String()
Dim ExplorerFiles As New List(Of String)
Dim exShell As New Shell
For Each window As ShellBrowserWindow In DirectCast(exShell.Windows, IShellWindows)
' check both for either interface to work
' add an Exit for to just work the first explorer window
If TryCast(window.Document, IShellFolderViewDual) IsNot Nothing Then
For Each fi As FolderItem In DirectCast(window.Document, IShellFolderViewDual).SelectedItems
ExplorerFiles.Add(fi.Path)
Next
ElseIf TryCast(window.Document, ShellFolderView) IsNot Nothing Then
For Each fi As FolderItem In DirectCast(window.Document, ShellFolderView).SelectedItems
ExplorerFiles.Add(fi.Path)
Next
End If
Next
Return ExplorerFiles.ToArray
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim files = GetExplorerSelectedFiles()
ListBox1.Items.AddRange(files)
End Sub
End Class
HTH