Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the list of open folders and directories in windows explorer in all windows versions from 7 to 10?
in C# or VB.Net

What I have tried:

VB
<pre>Imports Shell32 ' Add reference browse C:\Windows\System32\Shell32.dll or com Microsoft Shell Controls and Automation

'http://xkom.blogspot.com/2011/06/get-opened-folder-location-in-explorer.html

Public Class Form1

    Dim Lb As New ListBox

    Dim WithEvents RoutineTimer As New Timer

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Lb.Parent = Me
        Lb.Dock = DockStyle.Fill
        Me.Text = "Opened Folder by user (explorer)"
        RoutineTimer.Interval = 1000
        RoutineTimer.Start()

    End Sub

    Sub GetOpenedFolder()

        Dim MShell As New Shell
        Dim SFV As ShellFolderView

        Lb.Items.Clear()
        On Error Resume Next
        For Each o In MShell.Windows
            If TypeName(o.document) <> "HTMLDocument" Then
                SFV = o.document
                If SFV.Folder.Items.Count > 0 Then
                    Lb.Items.Add(TrimPath(CType(SFV.Folder.Items(0), ShellFolderItem).Path))
                End If
            End If
        Next

    End Sub

    Sub Timer_Job() Handles RoutineTimer.Tick
        GetOpenedFolder()
    End Sub

    Function TrimPath(ByRef s As String) As String
        Return s.Remove(InStrRev(s, "\"))
    End Function

End Class


I used this on windows 7 but not working on windows 10
Posted
Updated 1-May-18 8:59am
Comments
BillWoodruff 1-May-18 12:37pm    
Describe how it's "not working." Error message ? No result ? Strange result ?

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900