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:org.alfresco.util.xml.SchemaHelper.java

public static void main(String... args) {
    if (args.length < 2 || !args[0].startsWith("--compile-xsd=") && !args[1].startsWith("--output-dir=")) {
        System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>");
        System.exit(1);/*from  w w  w .j a v  a  2 s .  c  o  m*/
    }
    final String urlStr = args[0].substring(14);
    if (urlStr.length() == 0) {
        System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>");
        System.exit(1);
    }
    final String dirStr = args[1].substring(13);
    if (dirStr.length() == 0) {
        System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>");
        System.exit(1);
    }
    try {
        URL url = ResourceUtils.getURL(urlStr);
        File dir = new File(dirStr);
        if (!dir.exists() || !dir.isDirectory()) {
            System.out.println("Output directory not found: " + dirStr);
            System.exit(1);
        }

        ErrorListener errorListener = new ErrorListener() {
            public void warning(SAXParseException e) {
                System.out.println("WARNING: " + e.getMessage());
            }

            public void info(SAXParseException e) {
                System.out.println("INFO: " + e.getMessage());
            }

            public void fatalError(SAXParseException e) {
                handleException(urlStr, e);
            }

            public void error(SAXParseException e) {
                handleException(urlStr, e);
            }
        };

        SchemaCompiler compiler = XJC.createSchemaCompiler();
        compiler.setErrorListener(errorListener);
        compiler.parseSchema(new InputSource(url.toExternalForm()));
        S2JJAXBModel model = compiler.bind();
        if (model == null) {
            System.out.println("Failed to produce binding model for URL " + urlStr);
            System.exit(1);
        }
        JCodeModel codeModel = model.generateCode(null, errorListener);
        codeModel.build(dir);
    } catch (Throwable e) {
        handleException(urlStr, e);
        System.exit(1);
    }
}

From source file:eu.scape_project.cdx_creator.CDXCreator.java

/**
 * Main entry point.//  w w  w  .  j  av  a2  s .  c om
 *
 * @param args
 * @throws java.io.IOException
 * @throws org.apache.commons.cli.ParseException
 */
public static void main(String[] args) throws IOException, ParseException {
    Configuration conf = new Configuration();
    // Command line interface
    config = new CDXCreatorConfig();
    CommandLineParser cmdParser = new PosixParser();
    GenericOptionsParser gop = new GenericOptionsParser(conf, args);
    CDXCreatorOptions cdxCreatorOpts = new CDXCreatorOptions();
    CommandLine cmd = cmdParser.parse(cdxCreatorOpts.options, gop.getRemainingArgs());
    if ((args.length == 0) || (cmd.hasOption(cdxCreatorOpts.HELP_OPT))) {
        cdxCreatorOpts.exit("Help", 0);
    } else {
        cdxCreatorOpts.initOptions(cmd, config);
    }

    // configuration properties
    if (config.getPropertiesFilePath() != null) {
        pu = new PropertyUtil(config.getPropertiesFilePath(), true);
    } else {
        pu = new PropertyUtil("/eu/scape_project/cdx_creator/config.properties", false);
    }

    config.setCdxfileCsColumns(pu.getProp("cdxfile.cscolumns"));
    config.setCdxfileCsHeader(pu.getProp("cdxfile.csheader"));

    CDXCreator cdxCreator = new CDXCreator();

    File input = new File(config.getInputStr());

    if (input.isDirectory()) {
        config.setDirectoryInput(true);
        cdxCreator.traverseDir(input);
    } else {
        CDXCreationTask cdxCreationTask = new CDXCreationTask(config, input, input.getName());
        cdxCreationTask.createIndex();
    }

    System.exit(0);
}

From source file:com.siva.filewritterprogram.Mp3FileWritterTool.java

public static void main(String[] args) {
    File directory = new File("D:\\Siva\\Entertainment\\EvergreenHits");

    FileFilter filter = new FileFilter() {
        @Override//from  w w w. ja  va 2  s  .  c  om
        public boolean accept(File file) {
            if (file.getName().endsWith(".mp3")) {
                return true;
            } else {
                return false;
            }
        }
    };
    File[] subdirs = directory.listFiles();
    for (File subDir : subdirs) {
        try {
            System.out.println("Going to read files under : " + subDir);
            if (subDir.isDirectory()) {
                File[] files = subDir.listFiles(filter);
                if (files != null) {
                    for (File file : files) {
                        FileUtils.copyFileToDirectory(file, new File(directory.getPath() + "\\toTransfer"));
                    }
                } else {
                    System.out.println("There are no songs inside. [" + subDir.getName() + "]");
                }
            } else {
                System.out.println("Not a directory. [" + subDir.getName() + "]");
            }
        } catch (IOException ex) {
            Logger.getLogger(Mp3FileWritterTool.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:FindDirectories.java

public static void main(String[] args) {
    // if no arguments provided, start at the parent directory
    if (args.length == 0)
        args = new String[] { ".." };

    try {//from w  w w .ja  va 2s  .  c om
        File pathName = new File(args[0]);
        String[] fileNames = pathName.list();

        // enumerate all files in the directory
        for (int i = 0; i < fileNames.length; i++) {
            File f = new File(pathName.getPath(), fileNames[i]);

            // if the file is again a directory, call the main method recursively
            if (f.isDirectory()) {
                System.out.println(f.getCanonicalPath());
                main(new String[] { f.getPath() });
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:dk.statsbiblioteket.util.qa.PackageScannerDriver.java

/**
 * @param args The command line arguments.
 * @throws IOException If command line arguments can't be passed or there
 *                     is an error reading class files.
 *///from www . jav  a  2  s.  co m
@SuppressWarnings("deprecation")
public static void main(final String[] args) throws IOException {
    Report report;
    CommandLine cli = null;
    String reportType, projectName, baseSrcDir, targetPackage;
    String[] targets = null;

    // Build command line options
    CommandLineParser cliParser = new PosixParser();
    Options options = new Options();
    options.addOption("h", "help", false, "Print help message and exit");
    options.addOption("n", "name", true, "Project name, default 'Unknown'");
    options.addOption("o", "output", true, "Type of output, 'plain' or 'html', default is html");
    options.addOption("p", "package", true, "Only scan a particular package in input dirs, use dotted "
            + "package notation to refine selections");
    options.addOption("s", "source-dir", true,
            "Base source dir to use in report, can be a URL. " + "@FILE@ and @MODULE@ will be escaped");

    // Parse and validate command line
    try {
        cli = cliParser.parse(options, args);
        targets = cli.getArgs();
        if (args.length == 0 || targets.length == 0 || cli.hasOption("help")) {
            throw new ParseException("Not enough arguments, no input files");
        }
    } catch (ParseException e) {
        printHelp(options);
        System.exit(1);
    }

    // Extract information from command line
    reportType = cli.getOptionValue("output") != null ? cli.getOptionValue("output") : "html";

    projectName = cli.getOptionValue("name") != null ? cli.getOptionValue("name") : "Unknown";

    baseSrcDir = cli.getOptionValue("source-dir") != null ? cli.getOptionValue("source-dir")
            : System.getProperty("user.dir");

    targetPackage = cli.getOptionValue("package") != null ? cli.getOptionValue("package") : "";
    targetPackage = targetPackage.replace(".", File.separator);

    // Set up report type
    if ("plain".equals(reportType)) {
        report = new BasicReport();
    } else {
        report = new HTMLReport(projectName, System.out, baseSrcDir);
    }

    // Do actual scanning of provided targets
    for (String target : targets) {
        PackageScanner scanner;
        File f = new File(target);

        if (f.isDirectory()) {
            scanner = new PackageScanner(report, f, targetPackage);
        } else {
            String filename = f.toString();
            scanner = new PackageScanner(report, f.getParentFile(),
                    filename.substring(filename.lastIndexOf(File.separator) + 1));
        }
        scanner.scan();
    }

    // Cloce the report before we exit
    report.end();
}

From source file:com.antelink.sourcesquare.SourceSquare.java

public static void main(String[] args) {

    logger.debug("starting.....");

    final EventBus eventBus = new EventBus();

    AntepediaQuery query = new AntepediaQuery();

    SourceSquareEngine engine = new SourceSquareEngine(eventBus, query);

    ScanStatusManager manager = new ScanStatusManager(eventBus);
    manager.bind();/*from   www .  j a  v a  2 s  . c  om*/

    TreeMapBuilder treemap = new TreeMapBuilder(eventBus);
    treemap.bind();

    ResultBuilder builder = new ResultBuilder(eventBus, treemap);
    builder.bind();

    final SourceSquareFSWalker walker = new SourceSquareFSWalker(engine, eventBus, treemap);
    walker.bind();

    ServerController.bind(eventBus);
    if (args.length != 0) {
        final File toScan = new File(args[0]);

        if (!toScan.isDirectory()) {
            logger.error("The argument is not a directory");
            logger.info("exiting SourceSquare");
            System.exit(0);
        }

        eventBus.fireEvent(new StartScanEvent(toScan));

        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "SourceSquare");

        logger.info("Scan complete");
        logger.info("Number of files to scan: " + ScanStatus.INSTANCE.getNbFilesToScan());
        logger.info("Number of files Scanned: " + ScanStatus.INSTANCE.getNbFilesScanned());
        logger.info("Number of files open source: " + ScanStatus.INSTANCE.getNbOSFilesFound());
    } else {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e) {
            logger.info("Error launching the UI", e);
        } catch (InstantiationException e) {
            logger.info("Error launching the UI", e);
        } catch (IllegalAccessException e) {
            logger.info("Error launching the UI", e);
        } catch (UnsupportedLookAndFeelException e) {
            logger.info("Error launching the UI", e);
        }
        SourceSquareView view = new SourceSquareView();
        SourceSquareController controller = new SourceSquareController(view, eventBus);

        ExitSourceSquareView exitView = new ExitSourceSquareView();
        ExitController exitController = new ExitController(exitView, eventBus);

        exitController.bind();
        controller.bind();
        controller.display();
    }

}

From source file:de.peran.DependencyReadingStarter.java

public static void main(final String[] args) throws ParseException, FileNotFoundException {
    final Options options = OptionConstants.createOptions(OptionConstants.FOLDER, OptionConstants.STARTVERSION,
            OptionConstants.ENDVERSION, OptionConstants.OUT);

    final CommandLineParser parser = new DefaultParser();
    final CommandLine line = parser.parse(options, args);

    final File projectFolder = new File(line.getOptionValue(OptionConstants.FOLDER.getName()));

    final File dependencyFile;
    if (line.hasOption(OptionConstants.OUT.getName())) {
        dependencyFile = new File(line.getOptionValue(OptionConstants.OUT.getName()));
    } else {//from w  w w. ja  va  2  s . c o  m
        dependencyFile = new File("dependencies.xml");
    }

    File outputFile = projectFolder.getParentFile();
    if (outputFile.isDirectory()) {
        outputFile = new File(projectFolder.getParentFile(), "ausgabe.txt");
    }

    LOG.debug("Lese {}", projectFolder.getAbsolutePath());
    final VersionControlSystem vcs = VersionControlSystem.getVersionControlSystem(projectFolder);

    System.setOut(new PrintStream(outputFile));
    // System.setErr(new PrintStream(outputFile));

    final DependencyReader reader;
    if (vcs.equals(VersionControlSystem.SVN)) {
        final String url = SVNUtils.getInstance().getWCURL(projectFolder);
        final List<SVNLogEntry> entries = getSVNCommits(line, url);
        LOG.debug("SVN commits: "
                + entries.stream().map(entry -> entry.getRevision()).collect(Collectors.toList()));
        reader = new DependencyReader(projectFolder, url, dependencyFile, entries);
    } else if (vcs.equals(VersionControlSystem.GIT)) {
        final List<GitCommit> commits = getGitCommits(line, projectFolder);
        reader = new DependencyReader(projectFolder, dependencyFile, commits);
        LOG.debug("Reader initalized");
    } else {
        throw new RuntimeException("Unknown version control system");
    }
    reader.readDependencies();
}

From source file:Main.java

public static void main(String[] args) {

    File workingDirectory = new File("C:" + File.separator + "Invoices");

    File template = new File(workingDirectory.getAbsolutePath() + File.separator + "invoiceTemplate.tex");

    File tempDir = new File(workingDirectory.getAbsolutePath() + File.separator + "temp");
    if (!tempDir.isDirectory()) {
        tempDir.mkdir();//from w  w w.  j  av  a  2  s.c om
    }

    File invoice1 = new File(tempDir.getAbsolutePath() + File.separator + "invoice1.tex");
    File invoice2 = new File(tempDir.getAbsolutePath() + File.separator + "invoice2.tex");

    try {

        HashMap<String, String> data = new HashMap<String, String>();

        data.put("Number", "1");
        data.put("Customer name", "Ivan Pfeiffer");
        data.put("Customer street", "Schwarzer Weg 4");
        data.put("Customer zip", "13505 Berlin");
        data.put("Development", "Software");
        data.put("Price", "500");

        JLRConverter converter = new JLRConverter("::", ":::");
        if (!converter.parse(template, invoice1, data)) {
            System.out.println(converter.getErrorMessage());
        }

        data.put("Number", "2");
        data.put("Customer name", "Mike Mueller");
        data.put("Customer street", "Prenzlauer Berg 12");
        data.put("Customer zip", "10405 Berlin");
        data.put("Development", "Hardware");
        data.put("Price", "2350");

        if (!converter.parse(template, invoice2, data)) {
            System.out.println(converter.getErrorMessage());
        }

        File desktop = new File(System.getProperty("user.home") + File.separator + "Desktop");

        JLRGenerator pdfGen = new JLRGenerator();

        pdfGen.deleteTempTexFile(false);

        if (!pdfGen.generate(invoice1, desktop, workingDirectory)) {
            System.out.println(pdfGen.getErrorMessage());
        }

        JLROpener.open(pdfGen.getPDF());

        if (!pdfGen.generate(invoice2, desktop, workingDirectory)) {
            System.out.println(pdfGen.getErrorMessage());
        }

        JLROpener.open(pdfGen.getPDF());

    } catch (IOException ex) {
        System.err.println(ex.getMessage());
    }
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame(Main.class.getSimpleName());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JTree tree = new JTree(createTreeModel(new File(System.getProperty("user.dir")), true));
    tree.setCellRenderer(new DefaultTreeCellRenderer() {
        @Override/*  ww  w .j  a va2 s  .com*/
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
                if (node.getUserObject() instanceof File) {
                    setText(((File) node.getUserObject()).getName());
                }
            }
            return this;
        }
    });
    tree.getSelectionModel().addTreeSelectionListener(e -> {
        Object object = tree.getLastSelectedPathComponent();
        if (object instanceof DefaultMutableTreeNode) {
            Object userObject = ((DefaultMutableTreeNode) object).getUserObject();
            if (userObject instanceof File) {
                File file = (File) userObject;
                System.out.println(
                        "Selected file" + file.getAbsolutePath() + " Is directory? " + file.isDirectory());
            }
        }
    });
    JScrollPane pane = new JScrollPane(tree);
    frame.add(pane);
    frame.setSize(400, 600);
    frame.setVisible(true);
}

From source file:com.osrdata.etltoolbox.fileloader.Main.java

/**
 * Main entry point into the application.
 * @param args command line argunemtns//from   ww w . j a  va2s.com
 */
public static void main(String[] args) {
    Options options = new Options();
    options.addOption(new Option("s", "spec", true, "Source-to-target specification file"));
    options.addOption(new Option("d", "directory", true, "Source directory to load"));
    options.addOption(new Option("f", "file", true, "File to perform operation on"));
    options.addOption(new Option("r", "replace", false, "Replace previously loaded data"));
    options.addOption(new Option("t", "trace", true, "Trace records processed at specified interval"));

    CommandLineParser parser = new BasicParser();

    try {
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("spec") && (line.hasOption("directory") || line.hasOption("file"))) {
            FileLoader loader = new FileLoader(line);

            loader.init();

            if (line.hasOption("file")) {
                loader.load(new File(line.getOptionValue("file")));
            } else if (line.hasOption("directory")) {
                File directory = new File(line.getOptionValue("directory"));

                if (directory.isDirectory()) {
                    File[] files = directory.listFiles();

                    for (File file : files) {
                        loader.load(file);
                    }
                } else {
                    log.fatal(directory.getAbsolutePath() + " does not appear to be a directory.");
                }
            }
        } else {
            usage();
        }
    } catch (ParseException e) {
        usage();
    } catch (IOException e) {
        e.printStackTrace();
    }
}