Open windows explorer select file

C#: How to open Windows Explorer windows with a number of files selected

In the Library of Windows Media Player you can select one or more music files. You can then right-click and in their context menu choose Open File Location. This will open up one windows explorer window for each directory that the files are in, and the files will be selected for you.

So let’s say we have a bunch of mp3 files in our library where three of them are these:

  • Z:\Music\Thursday Blues\01. I wish it was friday.mp3
  • Z:\Music\Counting Sheep\01. Sheep #1.mp3
  • Z:\Music\Counting Sheep\02. Sheep #2.mp3

If we select those three (in a view where all of them are visible) and do Open File Location then two explorer windows will pop up. One will be the Z:\Music\Thursday Blues folder with 01. I wish it was friday.mp3 selected, and the other one will be the *Z:\Music\Counting Sheep** folder with both 01. Sheep #1.mp3 and 02. Sheep #2.mp3 selected.

How can I do this myself in C#? We have an application which is going to export data to various formats, for example CSV and Excel, and I would like to open up explorer windows with these files selected when they are created and ready to be viewed. Currently I just do Process.Start(path) , and this works but I would love to be able to highlight those particular files as well. Would make the files that were just created much more obvious.

Windows Media Player does it so well. I want to do it too =/ Are there any Microsoft employees here that could figure out how it can be done? (A)

Opening a folder in explorer and selecting a file

I’m trying to open a folder in explorer with a file selected.

The following code produces a file not found exception:

How can I get this command to execute in C#?

11 Answers 11

First argument is an application (explorer.exe), second method argument are arguments of the application you run.

If your path contains comma’s, putting quotes around the path will work when using Process.Start(ProcessStartInfo).

It will NOT work when using Process.Start(string, string) however. It seems like Process.Start(string, string) actually removes the quotes inside of your args.

Here is a simple example that works for me.

Just my 2 cents worth, if your filename contains spaces, ie «c:\My File Contains Spaces.txt», you’ll need to surround the filename with quotes otherwise explorer will assume that the othe words are different arguments.

Using Process.Start on explorer.exe with the /select argument oddly only works for paths less than 120 characters long.

I had to use a native windows method to get it to work in all cases:

Samuel Yang answer tripped me up, here is my 3 cents worth.

Adrian Hum is right, make sure you put quotes around your filename. Not because it can’t handle spaces as zourtney pointed out, but because it will recognize the commas (and possibly other characters) in filenames as separate arguments. So it should look as Adrian Hum suggested.

Notice there should be a comma after /select instead of space..

Читайте также:  Windows 10 latest version build 16299

The most possible reason for it not to find the file is the path having spaces in. For example, it won’t find «explorer /select,c:\space space\space.txt».

Just add double quotes before and after the path, like;

or do the same in C# with

You need to put the arguments to pass («/select etc») in the second parameter of the Start method.

It might be a bit of a overkill but I like convinience functions so take this one:

This is the extension function I use as .Quote():

Not the answer you’re looking for? Browse other questions tagged c# explorer or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Programmatically select multiple files in windows explorer

I can display and select a single file in windows explorer like this:

However, I can’t work out how to select more than one file. None of the permutations of select I’ve tried work.

Note: I looked at these pages for docs, neither helped.

8 Answers 8

This should be possible with the shell function SHOpenFolderAndSelectItems

EDIT

Here is some sample code showing how to use the function in C/C++, without error checking:

The true way of selecting multiple files in Explorer is the next

Unmanaged code looks like this (compiled from China code posts with fixing its bugs)

it cannot be done through explorer.exe

Depending on what you actually want to accomplish you may be able to do it with AutoHotKey. It is an amazing free tool for automating things you normally can’t do. It should come with Windows. This script will select your file and highlight the next two files below it when you hit F12.

It is also possible to just put those two middle lines in a text file and then pass it is a parm to autohotkey.exe. They have an option to compile the script also, which would make it a standalone exe that you could call. Works great with a great help file.

@Orion, It is possible to use autohotkey from C#. You can make an autohotkey script into a standalone executable (about 400k) that can be launched by your C# app (just the way you are launching explorer). You can also pass it command line parameters. It does not have any runtime requirements.

This is one of those questions where it may be good to consider what you’re trying to achieve, and whether there’s a better method.

To add some more context — Our company develops a C# client application, which allows users to load files and do stuff with them, kind of like how iTunes manages your MP3 files without showing you the actual file on disk.

It’s useful to select a file in the application, and do a ‘Show me this file in Windows Explorer` command — this is what I’m trying to achieve, and have done so for single files.

We have a ListView which allows users to select multiple files within the application, and move/delete/etc them. It would be nice to have this ‘show me this file in windows’ command work for multiple selected files — at least if all the source files are in the same directory, but if it’s not possible then it’s not a major feature.

How to select file on an open explorer window with java

i’m trying to make a program that downloads some files, and now i want to open the folder (on the windows explorer) where those files are (it’s always the same folder) and select the last file that was downloaded, i found this code to do it on java:

It works, but every time i press the button to open the folder it opens a new folder to select the file so i end up with many windows opened. Is there a way to do this on the folder that is already open?

I’ve been looking on the web for this but i only found the same code that i’m already using. All of those other posts about this issue are from many years ago so i don’t know if it used to work that way on previous versions.

Thank you so much if any of you can help me.

Читайте также:  При стандартной установке windows вы можете одним щелчком мыши

1 Answer 1

It’s easier to implement in C#, but not impossible in Java though you will need to setup native Windows calls via JNI code, JNA or with Java JDK 16 Panama project. A not-accepted answer in the comment mentioned by @Abra has a good way to implement using the Windows API SHOpenFolderAndSelectItems. SHOpenFolderAndSelectItems moves the Explorer view to the foreground if it is hidden, changes the selected files according to the new parameters, and works for multiple selections in the same directory.

This is an all-in-one definition of a class that implements SHOpenFolderAndSelectItems in pure Java using Early Access JDK16 Project Panama build 16-panama+3-385 so there is no guarantee it will work at the next release cycle, but demonstrates how native code may get easier to do after JDK16/17.

The main is very straightforward but requires JDK Panama release and parameters to enable:

I have inlined various methods from my own classes below into one implementation class so it not very pretty structure.

How to open File Explorer and Windows Explorer: 12 ways

File Explorer is one of the most used apps in Windows 10, just like Windows Explorer is one of the most used tools in Windows 7. Whether you need to copy or move files or delete some, there is always one thing that you have to do first, and that is to open the File Explorer or the Windows Explorer. We thought it would be an excellent idea to write this roundup article, showing all the ways in which you can open File Explorer in Windows 10 and how to open Windows Explorer in Windows 7. They involve everything from search to keyboard shortcuts, to using speech, and so on. Let’s get started:

Quick Steps:

  1. Press the Win + E keys on your keyboard, and watch File Explorer or Windows Explorer immediately start.
  2. Click or tap the File Explorer/Windows Explorer shortcut on the taskbar.
  3. Open CMD or PowerShell and run the command: explorer.

NOTE: This guide covers Windows 10 and Windows 7. If you don’t know the Windows version you have, read this tutorial: What version of Windows do I have installed? (5 methods).

1. Open (Windows) File Explorer by pressing Win + E on your keyboard

The keyboard offers fast shortcuts for launching all kinds of things, including File Explorer and Windows Explorer. Press the Win + E keys on your keyboard, and watch File Explorer or Windows Explorer immediately start.

Open (Windows) File Explorer by pressing Win + E on your keyboard

2. Use the File Explorer shortcut (or Windows Explorer shortcut) on the taskbar

By default, Windows 10 includes a File Explorer shortcut on the taskbar. The icon looks like a folder. Click or tap on it, and File Explorer is opened.

Use the File Explorer shortcut on the taskbar

Similarly, Windows 7 includes a Windows Explorer shortcut on its taskbar. The icon looks a bit different from the one in Windows 10, but it also depicts a folder.

Use the Windows Explorer shortcut on the taskbar

3. How to open File Explorer (or Windows Explorer) using search

On Windows 10’s desktop, use the search box found near the Start button on the taskbar and, inside it, write the words “file explorer.” When the search results are loaded, press Enter or click or tap on the File Explorer result.

How to open File Explorer in Windows 10 using search

In Windows 7, open the Start Menu and type the words “windows explorer” in its search box.

Then, click on the Windows Explorer shortcut.

How to open Windows Explorer in Windows 7 using search

4. Open File Explorer in Windows 10 using Cortana

In Windows 10, you can also ask Cortana to open File Explorer. On the right side of the search box from your taskbar, click or tap on Cortana’s button. Then, either type “open File Explorer” or push the microphone button and use your voice to say the “Open File Explorer!” command to Cortana.

Open File Explorer in Windows 10 using Cortana

5. How to open File Explorer in Windows 10 using its shortcut from the WinX menu

If you use Windows 10, press Windows + X on the keyboard to open the WinX menu. You can also right-click on the Start button to get the same result. This menu also includes a shortcut for File Explorer. Click or tap on it, and File Explorer opens immediately.

How to open File Explorer in Windows 10 using its shortcut from the WinX menu

Читайте также:  Pycharm ��� linux 32 bit

6. How to open File Explorer or Windows Explorer using their shortcuts from the Start Menu

In Windows 10, open the Start Menu and scroll the list with all the apps until you reach the folder called “Windows System.” Open it, and you should find a shortcut for File Explorer inside.

How to open File Explorer using its shortcuts from the Start Menu

In Windows 7, open the Start Menu and enter the Accessories folder. You should find a shortcut for Windows Explorer.

How to open Windows Explorer using its shortcut from the Start Menu

7. Open File Explorer using its button from Windows 10’s Start Menu

Another way to open File Explorer in Windows 10 is to add a button for it in the Start Menu. You can easily do it by opening Settings, navigating to “Personalization -> Start -> Choose which folders appear on Start,” and then turning on the File Explorer switch.

Enable File Explorer in Settings -> Personalization -> Start -> Choose which folders appear on Start

Then, Windows 10 shows a new button for File Explorer on the left side of the Start Menu.

How to open File Explorer in Windows 10 using its button from the Start Menu

Click or tap on it to open File Explorer.

8. How to create a File Explorer shortcut to open it from anywhere

You can always make a shortcut to File Explorer. If you’re using Windows 10, an easy way to do it is to drag and drop the File Explorer shortcut from the Start Menu onto your desktop or in any other folder you prefer.

File Explorer shortcut pinned to the desktop of Windows 10

Another one is to create a File Explorer shortcut or Windows Explorer shortcut manually. Just make sure to enter explorer as the shortcut’s “[…] location of the item”.

Create (Windows) File Explorer shortcut

NOTE: If you need help creating shortcuts, read how to Create shortcuts for apps, files, folders, and web pages in Windows 10. Although this tutorial is written for Windows 10, the first sections from it also apply to Windows 7.

9. Open (Windows) File Explorer using Command Prompt or PowerShell

If you are working with Command Prompt or PowerShell, you can type the command explorer and press Enter. This immediately launches File Explorer in Windows 10 or Windows Explorer in Windows 7.

Open (Windows) File Explorer using Command Prompt or PowerShell

10. How to open File Explorer or Windows Explorer using Task Manager

Another way of opening File Explorer or Windows Explorer is to use the Task Manager. Launch Task Manager: a quick way to do it is to press the Ctrl + Shift + Esc keys on your keyboard. If you are using Windows 10 and the Task Manager opens up in its compact view mode, click or tap on “More details.” Then, open the File menu and click or tap on “Run new task.”

Run new task in Task Manager

In the “Create new task” window, type explorer and press Enter or OK.

How to open File Explorer or Windows Explorer using Task Manager

11. Open File Explorer or Windows Explorer from the Run window

The final method we know of for opening File Explorer is to use the good old Run window. Launch Run (a quick way to do that is to press the Win + R keys on your keyboard) and enter the word explorer in it. Then click or tap on OK, or press Enter on your keyboard.

Open File Explorer or Windows Explorer from the Run window

12. Where is File Explorer in Windows 10 (and Windows 7)? Open it by running explorer.exe

Both Windows 10 and Windows 7 store the executable file for File Explorer in the standard Windows folder. As a result, although it’s kind of redundant, you can also navigate to your Windows folder and then double-click on the explorer.exe file to open File Explorer or Windows Explorer.

Where is File Explorer in Windows 10 (and 7)? Open it by running explorer.exe

How do you open (Windows) File Explorer?

These are all the methods we know for starting File Explorer in Windows 10 and Windows Explorer in Windows 7. If you know others, don’t hesitate to share them in the comments section below, and we will update this article as soon as possible.

Оцените статью