-3

In my application I need to select files with out file extension using file dialog. Is there a way to achieve this? Please help me to find a solution for this. My current code with out any filter is given below:

@Override
            public void handleEvent(Event event) {

                FileDialog dialog = new FileDialog(shell, SWT.NONE);
                String filePath = dialog.open();
                if (filePath != null && !filePath.equals("")) {
                    //Do my Operations

                }

            }
Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
EJoe
  • 55
  • 8
  • 4
    Yes, there is a way to achieve this. – Georgian Dec 20 '13 at 09:52
  • Check [this post](http://stackoverflow.com/questions/7211107/how-to-use-filedialog) – Ceiling Gecko Dec 20 '13 at 09:54
  • when the dialog is shown up to select a file, you need to display only the file which are without any extensions (means flat files) ? Am i rite? – AJJ Dec 20 '13 at 10:02
  • 1
    Yes.I need to display files without any extensions with *.txt files – EJoe Dec 20 '13 at 10:09
  • 1
    Hi GGrec,Thanks for the replay.I read the link shared by you.It only says how to filter files with extensions. I want to filter files without extensions. – EJoe Dec 20 '13 at 10:30
  • @EJoe it cannot be done. You can not filter and show only the files without extension. You can filter and show only files with extension. See http://superuser.com/questions/691083/view-only-files-without-extension-in-file-choose-windows-7/691094?noredirect=1#691094 – AJJ Dec 20 '13 at 11:42

1 Answers1

4

FileNameExtensionFilter class won't allow you to filter with empty extensions. So, create your own FileFilter.

FileFilter filterWithoutExtension = new FileFilter() {

        @Override
        public boolean accept(File f) {
            // This will display only the files without "."
            return !f.getName().contains(".");
        }

        @Override
        public String getDescription() {
            return "Files Without Extension";
        }
};

Then set this one as your FileFilter.

myFileChooser.setFileFilter(filterWithoutExtension);
Nirmal Raghavan
  • 572
  • 7
  • 20
  • Is there any way to achieve this using FileDialog.Is it possible to create my own FileFilter and use it with fileDialog?. – EJoe Dec 23 '13 at 13:08