Example usage for java.io File isDirectory

List of usage examples for java.io File isDirectory

Introduction

In this page you can find the example usage for java.io File isDirectory.

Prototype

public boolean isDirectory() 

Source Link

Document

Tests whether the file denoted by this abstract pathname is a directory.

Usage

From source file:FileListFilter.java

public static void main(String[] args) {
    File myDir = new File("C:/");
    FilenameFilter select = new FileListFilter("F", "txt");
    File[] contents = myDir.listFiles(select);
    for (File file : contents) {
        System.out.println(file + " is a " + (file.isDirectory() ? "directory" : "file") + " last modified on\n"
                + new Date(file.lastModified()));
    }//from w  w w.j  a v a  2s  .c o  m
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String[] properties = { "os.name", "java.version", "java.vm.version", "java.vendor" };
    for (String property : properties) {
        System.out.println(property + ": " + System.getProperty(property));
    }//from  ww w  . j a  v  a2 s  .c o m
    JFileChooser jfc = new JFileChooser();
    jfc.showOpenDialog(null);
    jfc.addChoosableFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(".obj");
        }

        @Override
        public String getDescription() {
            return "Wavefront OBJ (*.obj)";
        }

        @Override
        public String toString() {
            return getDescription();
        }
    });
    int result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?");
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.updateComponentTreeUI(jfc);
    jfc.showOpenDialog(null);
    result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?");

    result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?");
    for (UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            SwingUtilities.updateComponentTreeUI(jfc);
            break;
        }
    }
    jfc.showOpenDialog(null);
    result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?");
}

From source file:Main.java

public static void main(String[] args) {
    File games = new File("C:\\Test");
    File[] files = games.listFiles();
    for (File file : files) {
        System.out.println(file + " is a " + (file.isDirectory() ? "directory" : "file"));
    }/*from ww w.  j a v  a  2 s  .  co  m*/
    String[] xfiles = games.list();
    for (String file : xfiles) {
        System.out.println("File = " + file);
    }
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            if (name.endsWith(".txt")) {
                return true;
            }
            return false;
        }
    };

    File[] yfiles = games.listFiles(filter);
    for (File doc : yfiles) {
        System.out.println("Doc file = " + doc);
    }
}

From source file:MainClass.java

public static void main(String[] a) {
    File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java");
    System.out.println(myFile.isDirectory());
}

From source file:FileFilterDemo.java

public static void main(String[] args) {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));

    chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".gif") || f.isDirectory();
        }/*from  w ww.j  ava  2 s .  c om*/

        public String getDescription() {
            return "GIF Images";
        }
    });

    int r = chooser.showOpenDialog(new JFrame());
    if (r == JFileChooser.APPROVE_OPTION) {
        String name = chooser.getSelectedFile().getName();
        System.out.println(name);
    }
}

From source file:com.cardFetcher.Core.NetrunnerCardFetcher.java

public static void main(String[] args) {
    //        String setsPath = "GameDatabase\\0f38e453-26df-4c04-9d67-6d43de939c77\\Sets";
    //        String imagesPath = "ImageDatabase\\0f38e453-26df-4c04-9d67-6d43de939c77\\Sets";
    String setsPath = "C:\\Users\\jose.gonzalez\\Documents\\OCTGN\\GameDatabase\\0f38e453-26df-4c04-9d67-6d43de939c77\\Sets";
    String imagesPath = "C:\\Users\\jose.gonzalez\\Documents\\OCTGN\\ImageDatabase\\0f38e453-26df-4c04-9d67-6d43de939c77\\Sets";
    //        String setsPath = "C:\\Users\\jgonzal2\\Documents\\OCTGN\\GameDatabase\\0f38e453-26df-4c04-9d67-6d43de939c77\\Sets";
    //        String imagesPath = "C:\\Users\\jgonzal2\\Documents\\OCTGN\\ImageDatabase\\0f38e453-26df-4c04-9d67-6d43de939c77\\Sets";

    try {/* w  ww  .  j av a  2 s  .  c  om*/
        JSONArray json = JSONFetcher.getJSON();
        //System.out.println(json);
        File f = new File(setsPath);
        File[] files = f.listFiles();
        int count = 0;
        for (File file : files) {
            if (file.isDirectory()) {
                Set s = XmlParser.parseXML(file.getCanonicalPath() + "\\set.xml");

                if ((!s.getSetName().equals("Promos")) && (!s.getSetName().equals("Markers"))) {
                    //System.out.println(s);
                    ImageFetcher fetch = new ImageFetcher(s, imagesPath, json);
                    System.out.print("thread " + count++ + ": ");
                    fetch.start();
                }
            }
        }
    }

    catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.blogspot.devsk.l2j.geoconv.GeoGonv.java

public static void main(String[] args) {

    if (args == null || args.length == 0) {
        System.out.println("File name was not specified, [\\d]{1,2}_[\\d]{1,2}.txt will be used");
        args = new String[] { "[\\d]{1,2}_[\\d]{1,2}.txt" };
    }/*  w  w w . j a v a2 s .c  om*/

    File dir = new File(".");
    File[] files = dir.listFiles((FileFilter) new RegexFileFilter(args[0]));

    ArrayList<File> checked = new ArrayList<File>();
    for (File file : files) {
        if (file.isDirectory() || file.isHidden() || !file.exists()) {
            System.out.println(file.getAbsoluteFile() + " was ignored.");
        } else {
            checked.add(file);
        }
    }

    if (OUT_DIR.exists() && OUT_DIR.isDirectory() && OUT_DIR.listFiles().length > 0) {
        try {
            System.out.println("Directory with generated files allready exists, making backup...");
            FileUtils.moveDirectory(OUT_DIR, new File("generated-backup-" + System.currentTimeMillis()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (!OUT_DIR.exists()) {
        OUT_DIR.mkdir();
    }

    for (File file : checked) {
        GeoConvThreadFactory.startThread(new ParseTask(file));
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    File myDir = new File("C:/");
    // Define a filter for java source files beginning with F
    FilenameFilter select = new FileListFilter("F", "java");

    File[] contents = myDir.listFiles(select);

    if (contents != null) {
        System.out.println(//w ww .j  a  va 2s  . c om
                "\nThe " + contents.length + " matching items in the directory, " + myDir.getName() + ", are:");
        for (File file : contents) {
            System.out.println(file + " is a " + (file.isDirectory() ? "directory" : "file")
                    + " last modified on\n" + new Date(file.lastModified()));
        }
    } else {
        System.out.println(myDir.getName() + " is not a directory");
    }
    return;
}

From source file:com.github.rinde.gpem17.Train.java

public static void main(String[] args) {
    if (args.length == 0) {
        run("files/config/gpem17.params");
    } else {//from  ww  w.  jav  a  2s  . c  om
        for (String file : args) {
            File f = new File(file);
            if (f.isDirectory()) {
                File[] paramFiles = f.listFiles(new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        return name.endsWith(".params");
                    }
                });

                Arrays.sort(paramFiles, new Comparator<File>() {
                    @Override
                    public int compare(File o1, File o2) {
                        return o1.getName().compareTo(o2.getName());
                    }
                });

                for (File paramFile : paramFiles) {
                    run(paramFile.getPath());
                }
            } else {
                run(file);
            }
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    // Change the dirPath value to list files from your directory
    String dirPath = "C:\\";

    File dir = new File(dirPath);
    File[] list = dir.listFiles();

    for (File f : list) {
        if (f.isFile()) {
            System.out.println(f.getPath() + "  (File)");
        } else if (f.isDirectory()) {
            System.out.println(f.getPath() + "  (Directory)");
        }/*www  . j a v  a2  s . c om*/
    }
}