Exploring Directories

Display directories Explorer-style with these two sneaky code snippets.

The first allows you to explore files in a particular folder. It simply opens the specified directory in single view mode, as though you’d clicked to it via 'My Computer' on the desktop.

To use this method, just run OpenDirectory and pass the relevant path.

The second snippet allows you to open the TreeView-like Windows Explorer, with the focus on a particular directory if required.

To use this method, just run OpenExplorer, passing an optional path to open with.

Note: If you do not pass valid paths, neither method will work.

Usage

OpenDirectory ("C:\")
OpenExplorer
OpenExplorer ("C:\Program Files\")

Code

Private Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal _
    lpOperation As String, ByVal lpFile As String, ByVal _
    lpParameters As String, ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

Private Const SW_SHOWNORMAL = 1

Public Sub OpenDirectory(Directory As String)

      ShellExecute 0, "Open", Directory, vbNullString, _
        vbNullString, SW_SHOWNORMAL

End Sub

Public Sub OpenExplorer(Optional InitialDirectory As String)

      ShellExecute 0, "Explore", InitialDirectory, _
        vbNullString, vbNullString, SW_SHOWNORMAL

End Sub


Blinds | Home Decorating Ideas | Boxgame Alle Nye Pc Spil Med Service | New York Limousines | Coverage Healthcare WA