2

I'm searching how to do the same as Open explorer on a file from SWT. Now i'm using Program.launch(someDirectoryPath);, but it opens Explorer within some directory, but select no file. Is possible in SWT open directory and select file in Explorer ?

Community
  • 1
  • 1
marioosh
  • 27,328
  • 49
  • 143
  • 192

1 Answers1

2

You need to pass some arguments when invoking the Explorer executable: http://support.microsoft.com/kb/152457

Example:

Explorer /select,C:\TestDir\TestApp.exe
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
maksimov
  • 5,792
  • 1
  • 30
  • 38
  • I don't want to open FileDialog. I need to open Windows Explorer with selection set on some file. Something like that: http://stackoverflow.com/questions/281888/open-explorer-on-a-file – marioosh May 24 '12 at 09:53
  • 1
    @marioosh I've updated my answer, but what does this have to do with Java or SWT? – maksimov May 24 '12 at 09:57
  • 1
    I need open Explorer **FROM** SWT. For example: `org.eclipse.swt.program.Program.launch("c:\\");` in Windows environment opens Explorer in `C:\` directory. I need the same but with opening Explorer in some directory and file selected. – marioosh May 24 '12 at 11:06
  • I did it. Thanks for that hint! `Runtime.getRuntime().exec("explorer.exe /select,C:\\someFile.txt");` – marioosh May 24 '12 at 11:17
  • I'm not sure if SWT will have a way to do that, but standard SDK provides a way: `Runtime.getRuntime().exec(new String[]{"explorer.exe","/select,C:\\TestDir\\TestApp.exe"});` EDIT: Ah, you've figured it out ;) – maksimov May 24 '12 at 11:19