Question

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

                }

            }
Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top