Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I try to select a file or directory which has a space in its path in the Windows Explorer, it selects a completely different directory:

explorer.exe "/select,C:\Program Files\foobar"

I've tried it from Java with

Runtime.getRuntime().exec(new String[] {
    "/select," + filePath

and with the above command line. In both cases, the same result. What can I do to solve the problem?

share|improve this question
up vote 1 down vote accepted

You'll have to quote the path (don't quote the /select, part).

Command line (tested):

explorer.exe /select,"C:\Program Files\foobar"

Java (not tested):

Runtime.getRuntime().exec(new String[] {
    "/select,\"" + filePath + "\""
share|improve this answer
Unfortunately, the solution works only on command line, but not for Java. – Mike L. Nov 29 '12 at 10:37
@MikeL. The Java-part of the question is better suited for StackOverflow. Maybe this can help:… – poplitea Nov 29 '12 at 11:16
OK, added following question:… – Mike L. Nov 29 '12 at 11:39

This works fine in JDK6.

Runtime.getRuntime().exec(new String[] {
"\"" + filePath + "\""});
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.