eclipse - This code creates a browse button to select a file. How do I change it to allow me to select a folder instead of a file inside a folder -


browsebutton = new button(controlgroupforsinglerun, swt.push);     browsebutton.settext("browse ...");     data = new griddata();     data.widthhint = 80;     browsebutton.setlayoutdata(data);     browsebutton.addselectionlistener(new selectionlistener(){         public void widgetselected(selectionevent event){             lookforexeclick();         }         public void widgetdefaultselected(selectionevent event){             widgetselected(event);         }     }); 

this code generates browse button on eclipse plugin gui, how can make button select directory , not specific file. right selecting file. can maybe provide me odified code allow happen. thank you.

as requested here lookforexclick() method.

so changed filedialog directorydialog answer below mentioned.  here method asked for:       private void lookforexeclick (){     boolean notlegal = false;     while(!notlegal){         exechooser.settext("choose executable file");          singleexefilepath = exechooser.open();          string tmp = exechooser.getfilename();          if(tmp.equals("")){             notlegal = true;             return;         }         else if(tmp == null){             notlegal = true;             return;         }         if(!tmp.equals("") && !tmp.endswith(".exe") && !tmp.endswith(".bat") && !tmp.endswith(".jar")){             messagedialog.openinformation(                 window.getshell(),                 "vulnerabilities viewer",                 "please input legal executable name!"                 );         }         else {             notlegal = true;         }     }      exelocationtext.settext(singleexefilepath);     pureexefilename = exechooser.getfilename();      // set selection newlocation.     last.setselection(false);     for(int = 0; < radios.length; i++){         radios[i].setselection(false);     }     newlocation.setselection(true); } 

what take out or comment browse button work directory selection. please me. thank you.

here snippet directorydialog, use instead of filedialog.

    directorydialog dlg = new directorydialog(display.getcurrent().getactiveshell());     string directorypath = dlg.open();     system.out.println(directorypath); 

edit: added lookforexeclick() here do, if understood code right:

private void lookforexeclick() {     directorydialog exechooser = new directorydialog(display.getdefault().getactiveshell());      string pureexefilename = null;      string directorypath = exechooser.open();     file directory = new file(directorypath);     (file file : directory.listfiles()) {         string filename = file.getname();         if (filename.endswith(".exe") || filename.endswith(".bat") || filename.endswith(".jar")) {             pureexefilename = filename;             break;         }     }      if (pureexefilename == null) {         messagedialog.openinformation(window.getshell(), "vulnerabilities viewer", "no exe file found in directory");         return;     }      exelocationtext.settext(pureexefilename);      // set selection newlocation.     last.setselection(false);     (int = 0; < radios.length; i++) {         radios[i].setselection(false);     }     newlocation.setselection(true); } 

edit: based on comment this:

    directorydialog dlg = new directorydialog(display.getcurrent().getactiveshell());     string directorypath = dlg.open();     file file = new file(directorypath, "myfilename.exe");      // if have generated file on file system     files.copy(sourcefile.topath(), file.topath(), standardcopyoption.replace_existing);      // if generate straight stream     fileoutputstream outputstream = new fileoutputstream(file); 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -