• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to open a folder?

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks you both it works.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
and POOF! You're gone! But look, this tiny ad is still here:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic