Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8941737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:22:21+00:00 2026-06-15T11:22:21+00:00

I would like to code a function to which you can pass a file

  • 0

I would like to code a function to which you can pass a file path, for example:

C:\FOLDER\SUBFOLDER\FILE.TXT

and it would open Windows Explorer with the folder containing the file and then select this file inside the folder. (Similar to the “Show In Folder” concept used in many programs.)

How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:22:22+00:00Added an answer on June 15, 2026 at 11:22 am

    Easiest way without using Win32 shell functions is to simply launch explorer.exe with the /select parameter. For example, launching the process

    explorer.exe /select,"C:\Folder\subfolder\file.txt"

    will open a new explorer window to C:\Folder\subfolder with file.txt selected.

    If you wish to do it programmatically without launching a new process, you’ll need to use the shell function SHOpenFolderAndSelectItems, which is what the /select command to explorer.exe will use internally. Note that this requires the use of PIDLs, and can be a real PITA if you are not familiar with how the shell APIs work.

    Here’s a complete, programmatic implementation of the /select approach, with path cleanup thanks to suggestions from @Bhushan and @tehDorf:

    public bool ExploreFile(string filePath) {
        if (!System.IO.File.Exists(filePath)) {
            return false;
        }
        //Clean up file path so it can be navigated OK
        filePath = System.IO.Path.GetFullPath(filePath);
        System.Diagnostics.Process.Start("explorer.exe", string.Format("/select,\"{0}\"", filePath));
        return true;
    }
    

    Reference: Explorer.exe Command-line switches

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to pass a series of 2D-arrays to a function, which then
I would like to play/pause video using jquery. Here is my code: (function ($)
I'd like to write a function that would have some optional code to be
I would like my c++ code to be as encapsulated as i can is
I would like to execute code sequentially in an NSOperation. This can be easily
In my UserProfile model I would like to have a function which returns either
I would like to define a function which returns the string NaN or sprintf(%g,val)
I would like to be able to do something like (psuedo-code): if (classAvailable) {
I have JSF code like: <h:inputText id=from value=#{fromToMBean.fromName}/> I would like to get this
I'm searching for the cleanest solution here. I would like to code a stored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.