/** Throws {@code FileNotFoundException} if file not found or current thread was interrupted */ ShellFolder getShellFolder(File f) throws FileNotFoundException { if (!(f instanceof ShellFolder) && !(f instanceof FileSystemRoot) && isFileSystemRoot(f)) { f = createFileSystemRoot(f); } try { return ShellFolder.getShellFolder(f); } catch (InternalError e) { System.err.println("FileSystemView.getShellFolder: f=" + f); e.printStackTrace(); return null; } }
/** Gets the list of shown (i.e. not hidden) files. */ public File[] getFiles(File dir, boolean useFileHiding) { List<File> files = new ArrayList<File>(); // add all files in dir if (!(dir instanceof ShellFolder)) { try { dir = getShellFolder(dir); } catch (FileNotFoundException e) { return new File[0]; } } File[] names = ((ShellFolder) dir).listFiles(!useFileHiding); if (names == null) { return new File[0]; } for (File f : names) { if (Thread.currentThread().isInterrupted()) { break; } if (!(f instanceof ShellFolder)) { if (isFileSystemRoot(f)) { f = createFileSystemRoot(f); } try { f = ShellFolder.getShellFolder(f); } catch (FileNotFoundException e) { // Not a valid file (wouldn't show in native file chooser) // Example: C:\pagefile.sys continue; } catch (InternalError e) { // Not a valid file (wouldn't show in native file chooser) // Example C:\Winnt\Profiles\joe\history\History.IE5 continue; } } if (!useFileHiding || !isHiddenFile(f)) { files.add(f); } } return files.toArray(new File[files.size()]); }