• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to open a folder?

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21227
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Henry pretty clearly suggested

Runtime.getRuntime().exec("explorer.exe C:\\eclipse 3.0\\dev");
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks you both it works.
 
Paul Clapham
Sheriff
Posts: 21154
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic