Example usage for java.io File listFiles

List of usage examples for java.io File listFiles

Introduction

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

Prototype

public File[] listFiles() 

Source Link

Document

Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.

Usage

From source file:com.hangum.tadpole.engine.initialize.JDBCDriverLoader.java

/**
 * add JAR Loader of dir/*from  w  w  w. j  a  va 2  s.  c om*/
 * 
 * @param strDir
 * @throws Exception
 */
public static void addJARDir(String strDir) throws Exception {
    //      if(logger.isDebugEnabled()) logger.debug("--> JAR path : " + strDir);

    File fileDir = new File(strDir);
    if (fileDir.isDirectory()) {
        File[] files = fileDir.listFiles();
        for (File file : files) {
            if (file.isDirectory()) {
                addJARDir(file.getAbsolutePath());
            } else {
                if (StringUtils.endsWithIgnoreCase(file.getName(), ".jar")) {
                    addJARLoader(new Object[] { file.toURI().toURL() });
                }
            }
        }

    } else {
        if (StringUtils.endsWithIgnoreCase(fileDir.getName(), ".jar")) {
            addJARLoader(new Object[] { fileDir.toURI().toURL() });
        }
    }
}

From source file:com.uas.Files.FilesDAO.java

public static void deleteAll(File folder) {
    File[] files = folder.listFiles();
    if (files != null) { //some JVMs return null for empty dirs
        for (File f : files) {

            f.delete();/*w  ww.  ja va 2 s. co  m*/

        }
    }

}

From source file:com.uas.Files.FilesDAO.java

public static void deleteFolder(File folder) {
    File[] files = folder.listFiles();
    if (files != null) { //some JVMs return null for empty dirs
        for (File f : files) {
            if (f.isDirectory()) {
                deleteFolder(f);//from  ww w  . j a va  2 s  .  co  m
            } else {
                f.delete();
            }
        }
    }

}

From source file:de.ingrid.iplug.csw.dsc.tools.FileUtils.java

/**
 * Remove all files from a directory and all sub directories
 * @param src The start directory// ww w  .  j a  v  a 2 s.  com
 */
public static void deleteRecursive(File src) {
    File[] files = src.listFiles();
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            if (file.isDirectory()) {
                deleteRecursive(file);
            }
            file.delete();
        }
    }
    src.delete();
}

From source file:net.rptools.maptool.client.AppSetup.java

public static void install() {
    File appDir = AppUtil.getAppHome();

    // Only init once
    if (appDir.listFiles().length > 0) {
        return;/*from  w  ww .j  a va  2 s .co m*/
    }
    try {
        installDefaultTokens();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}

From source file:Main.java

public static void deleteDirectory(File file) {
    if (file.isFile()) {
        file.delete();/* w w w .j a v  a2 s .co m*/
        return;
    }

    if (file.isDirectory()) {
        File[] childFiles = file.listFiles();
        if (childFiles == null || childFiles.length == 0) {
            file.delete();
            return;
        }

        for (int i = 0; i < childFiles.length; i++) {
            deleteDirectory(childFiles[i]);
        }
        file.delete();
    }
}

From source file:Main.java

public static void delete(File file) {
    if (file.isFile()) {
        file.delete();/*from w  ww  . ja  v a 2 s . c  o m*/
        return;
    }

    if (file.isDirectory()) {
        File[] childFiles = file.listFiles();
        if (childFiles == null || childFiles.length == 0) {
            file.delete();
            return;
        }

        for (int i = 0; i < childFiles.length; i++) {
            delete(childFiles[i]);
        }
        file.delete();
    }
}

From source file:br.edimarmanica.weir2.rule.type.RulesDataTypeController.java

/**
 * Persiste the datatype of each rule/*w w w  . j  a  v a  2s  .c  o  m*/
 *
 * @param site
 */
public static void persiste(Site site) {
    Map<String, DataType> ruleType = new HashMap<>();

    File dirInput = new File(Paths.PATH_INTRASITE + "/" + site.getPath() + "/extracted_values");
    for (File rule : dirInput.listFiles()) {
        ruleType.put(rule.getName(), RuleDataType.getMostFrequentType(rule));
    }

    File dirOutput = new File(Paths.PATH_WEIR_V2 + "/" + site.getPath());
    dirOutput.mkdirs();

    File file = new File(dirOutput.getAbsolutePath() + "/types.csv");
    String[] HEADER = { "RULE", "TYPE" };
    CSVFormat format = CSVFormat.EXCEL.withHeader(HEADER);

    try (Writer out = new FileWriter(file)) {
        try (CSVPrinter csvFilePrinter = new CSVPrinter(out, format)) {
            for (String rule : ruleType.keySet()) {
                List<String> dataRecord = new ArrayList<>();
                dataRecord.add(rule);
                dataRecord.add(ruleType.get(rule).name());
                csvFilePrinter.printRecord(dataRecord);
            }
        }
    } catch (IOException ex) {
        Logger.getLogger(RulesDataTypeController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.netflix.nicobar.core.utils.__JDKPaths.java

static void processDirectory1(final Set<String> pathSet, final File file, final String pathBase) {
    for (File entry : file.listFiles()) {
        if (entry.isDirectory()) {
            processDirectory1(pathSet, entry, pathBase);
        } else {// w w  w .  ja v a  2  s.c  o  m
            String packagePath = entry.getParent();
            if (packagePath != null) {
                packagePath = packagePath.substring(pathBase.length()).replace('\\', '/');
                if (packagePath.startsWith("/")) {
                    packagePath = packagePath.substring(1);
                }
                pathSet.add(packagePath);
            }
        }
    }
}

From source file:Main.java

public static void init(Context context) {
    voice_wechat_paths = new ArrayList<>();
    voice_qq_paths = new ArrayList<>();

    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File dir = Environment.getExternalStorageDirectory();
        File f = new File(dir + "/tencent/MicroMsg");

        if (f.exists() && f.canRead() && f.isDirectory()) {
            File[] files = f.listFiles();
            if (files == null || files.length == 0) {
                return;
            }/*from w w  w  .  java 2 s  .c  om*/

            for (File f0 : files) {
                if (f0.isDirectory() && f0.getName().length() > 24) {
                    voice_wechat_paths.add(f0.getAbsolutePath() + "/voice2");
                }
            }
        }

        File exportDir = new File(dir, "silkv3_mp3");
        if (!exportDir.exists()) {
            exportDir.mkdirs();
        }

        export_dir = exportDir.getAbsolutePath();
    }
}