| Author |
how to open a folder?
|
Peter Primrose
Ranch Hand
Joined: Sep 10, 2004
Posts: 755
|
|
hi guys, I have a gui where the user can click a button and the result should open a folder (C:/eclipse 3.0/dev) I'm trying: Runtime.getRuntime().exec(new String[] {"C:\\eclipse 3.0\\dev"}); but that doesn't work i get: java.io.IOException: CreateProcess: "C:\eclipse 3.0\dev" error=5 does anyone have any idea? thanks peter
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
I am assuming that this is for windows. (since you referred to the c: drive) You can't just execute a folder. Windows doesn't know what to do with it. I assume that you want to bring up a windows explorer -- set to the folder that you want. The command that you want is explorer.exe. And it should work if the first parameter is the folder name. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Peter Primrose
Ranch Hand
Joined: Sep 10, 2004
Posts: 755
|
|
thanks but I'm not sure: I tried diff variation: Runtime.getRuntime().exec(new String[] {"cd C:\\eclipse 3.0\\dev\\explorer.exe"}); or Runtime.getRuntime().exec(new String[] {"cd C:\\eclipse 3.0\\dev","explorer.exe"}); none works. mind to elaborate. thanks again
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24061
|
|
I think Henry pretty clearly suggested Runtime.getRuntime().exec("explorer.exe C:\\eclipse 3.0\\dev");
|
[Jess in Action][AskingGoodQuestions]
|
 |
Peter Primrose
Ranch Hand
Joined: Sep 10, 2004
Posts: 755
|
|
|
thanks you both it works.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
You can't just execute a folder. Windows doesn't know what to do with it. I assume that you want to bring up a windows explorer -- set to the folder that you want.
This isn't true. You can execute a folder. Go to your windows command line and type e.g. "start c:\windows" (without the quotes of course) and you'll see that it does exactly bring up a Windows Explorer set to that folder. So if you call Runtime.exec() on "cmd /c start c:\\..." it should do what you want. But you'll have problems if your directory name has spaces in it. Typing "help start" at your command line should explain how to deal with that.
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
Why do you want to open the folder in Explorer? If the user selects a file from the folder, your program won't know anything about it. Are you trying to let the user select a file or folder that will be used in your program in some way? If so, you should use a file dialog of some kind. If you are writing a Swing application, you might be interested in JFileChooser. If you are using plain AWT, look at FileDialog instead. Layne
|
Java API Documentation
The Java Tutorial
|
 |
 |
|
|
subject: how to open a folder?
|
|
|