I use

Shell("explorer Path")

Path is Directory
But it Open My Document
Path is D:/
I think It because The syntax "explorer Path" i try a lot like shell("explorer" path),
shell(explorer path) , shell(""explorer" path") but it always open My Document

Dani AI

Generated

A few quick, practical points that build on the replies from and :

The common cause for Explorer opening a default folder instead of your target is that the Shell call didn’t actually receive a valid folder argument (for example the literal text "Path" was passed, the variable was empty, or the program/argument weren’t separated/quoted correctly). The short Shell-based fix that used works, but in managed code it’s more reliable to use the .NET Process APIs.

Use Process.Start / ProcessStartInfo so the runtime handles quoting and execution cleanly. Example: open a folder only when it exists, and let the shell perform the open:

Dim folderPath As String = "D:\My Folder"
If System.IO.Directory.Exists(folderPath) Then
    Dim psi As New System.Diagnostics.ProcessStartInfo() With {
        .FileName = folderPath,
        .UseShellExecute = True
    }
    System.Diagnostics.Process.Start(psi)
End If

To open Explorer and highlight/select a file use the explorer switch /select: and make sure the path is quoted if it contains spaces:

Dim filePath As String = "C:\My Folder\file.txt"
Dim args As String = "/select,""" & filePath & """"
Dim psi As New System.Diagnostics.ProcessStartInfo("explorer.exe", args)
System.Diagnostics.Process.Start(psi)

Troubleshooting tips: verify the path with System.IO.Directory.Exists / File.Exists before calling; wrap paths that contain spaces in quotes; UNC/network paths sometimes behave differently; and prefer ProcessStartInfo.UseShellExecute = True when you need shell behavior. See the Process.Start documentation and the Explorer command-line options for details: Process.Start docs and .

Recommended Answers

All 2 Replies

Dim path="c:\folderName"
 Shell("c:\windows\explorer.exe" & " " & path)
commented: Thx adatapost u help me a lot +1

Thanks adatapost it work
I use

Shell("explorer " & Path)

It Smaller and works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.