Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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[] {
    "explorer.exe",
    "/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

2 Answers 2

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[] {
    "explorer.exe",
    "/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: stackoverflow.com/questions/4746953/… –  poplitea Nov 29 '12 at 11:16
1  
OK, added following question: stackoverflow.com/questions/13624961/… –  Mike L. Nov 29 '12 at 11:39

This works fine in JDK6.

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

Your Answer

 
discard

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.