I want to copy selected files in windows explorer, for example, if I push button, it will backup the selected files that is in the latest window. I get the path of all windows I opened, but I just want the latest window. Below is the method I found in this website.
Imports Shell32
Imports SHDocVw
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
Can I find the latest window I open, and make a backup?