Hi. I have a program that detects all the folders that are open and displays each one in a ListBox item.
What I want it to do is if a certain folder is closed, I want it to start a batch file and close itself. I know how to make it do these things but there's a problem. Here's my code:
Imports Shell32 Public Class Form1 Dim open As Integer Dim Lb As New ListBox Dim WithEvents RoutineTimer As New Timer Private Sub Form1_Load() Handles MyBase.Load Lb.Parent = Me Lb.Dock = DockStyle.Fill Me.Text = "XPLHHNSJKHF 1.0" RoutineTimer.Interval = 3000 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 'Scroll through all items in a listbox Dim itemText As String = Lb.ToString 'Get item string If itemText.Contains("C:\Users\David\Documents\My Documents\Computer Programs\David\KOAGCS") Then 'Check to see if item has our search var open = 1 End If MsgBox(open) 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
The problem is the If command for when we're checking the item isn't working. I don't know why. But it's not detecting it, and not setting the open variable to 1 like it should.
Can someone help me? Thanks.