Here you can find the source of directoryFetch(File starting)
Parameter | Description |
---|---|
starting | Starting directory. If you want to use the user's home directory, I suggest using <tt>System.getProperty("user.home")</tt> |
Parameter | Description |
---|---|
IllegalArgumentException | If the solitary param is non-existent or not a directory. |
public static File[] directoryFetch(File starting)
//package com.java2s; //License from project: Open Source License import java.io.File; import javax.swing.JFileChooser; public class Main { /**// w w w . j av a 2 s.co m * Creates a JFileChooser that allows user to select multiple directories. Program is exited if * user cancels/closes the dialog box. * * @param starting Starting directory. If you want to use the user's home directory, I suggest * using <tt>System.getProperty("user.home")</tt> * @return A list of Files representing directories the user selected. * @throws IllegalArgumentException If the solitary param is non-existent or not a directory. */ public static File[] directoryFetch(File starting) { if (!starting.isDirectory()) // idiot proofing throw new IllegalArgumentException("Specified directory does not exist or is not a directory"); JFileChooser fc = new JFileChooser(starting); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setDialogTitle("select directories"); fc.setMultiSelectionEnabled(true); if (fc.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) System.exit(0); return fc.getSelectedFiles(); } }