Results 1 to 5 of 5

Thread: [RESOLVED] Open Windows Explorer to folder opens Documents folder instead of Folder Path

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Resolved [RESOLVED] Open Windows Explorer to folder opens Documents folder instead of Folder Path

    Hi,

    When I have spaces and/or unusual characters in a folder path the following code opens the user's Documents folder instead of the intended path.
    Is there any way to fix it?
    Code:
            Dim FolderPath As String = "C:\A,B 1.1"
            If System.IO.Directory.Exists(FolderPath) Then
                Process.Start("explorer.exe", FolderPath)
            Else
                MsgBox("Path does not exist")
            End If

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,632

    Re: Open Windows Explorer to folder opens Documents folder instead of Folder Path

    Try passing FolderPath surrounded by double quotes.

    Multiple ways of doing this, one option:

    Code:
    Process.Start("explorer.exe", Chr(34) & FolderPath & Chr(34))
    Last edited by OptionBase1; Oct 24th, 2023 at 02:40 PM.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Open Windows Explorer to folder opens Documents folder instead of Folder Path

    As OB1 suggested, double quotes are needed...

    Code:
    Dim FolderPath As String = "C:\A,B 1.1"
    Process.Start("explorer.exe", String.Format("/n, /e, ""{0}""", "C:\A,B 1.1\"))
    See command line options here:

    https://ss64.com/nt/explorer.html

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Open Windows Explorer to folder opens Documents folder instead of Folder Path

    That's great.
    Thank you both.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] Open Windows Explorer to folder opens Documents folder instead of Fold

    This was not a programming problem. Process.Start basically just mimics what you can do from the commandline. You should have used a console window to get your commandline right first. If you'd done that then you'd have seen that quotes were required around a path that contained spaces. Of course they would be, given that spaces are the delimiters between arguments.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width