1

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?

chunlcw
  • 9
  • 1
  • ahh I see, you got it from [here](https://stackoverflow.com/questions/30990119/how-to-get-files-selected-in-explorer).. –  Apr 06 '20 at 19:24
  • Create a `List` to store the selected files, when you run this code again, any file that does not exist in the list is a new selected file. –  Apr 06 '20 at 19:30

0 Answers0