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:alilibs.AliFile.java

public static File[] getFiles2(File f) {

    return f.listFiles();
}

From source file:Main.java

public static long folderSize(File directory) {
    long length = 0;
    try {//from   www .  j  a  v  a  2 s . co m
        for (File file : directory.listFiles()) {

            if (file.isFile())
                length += file.length();
            else
                length += folderSize(file);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return length;
}

From source file:com.gargoylesoftware.js.CodeUpdater.java

private static void process(final File dir, final boolean isMain) throws IOException {
    for (final File file : dir.listFiles()) {
        if (file.isDirectory()) {
            process(file, isMain);/* ww w.j  a v a2s  .  c  o  m*/
        } else if (file.getName().endsWith(".java") && !file.getName().equals("package-info.java")) {
            processFile(file, isMain);
        }
    }
}

From source file:Main.java

private static final void zip(File directory, File base, ZipOutputStream zos) throws IOException {
    File[] files = directory.listFiles();
    byte[] buffer = new byte[8192];
    int read = 0;
    for (int i = 0, n = files.length; i < n; i++) {
        if (files[i].isDirectory()) {
            zip(files[i], base, zos);/*from  w  ww .  j av  a  2  s.  c om*/
        } else {
            FileInputStream in = new FileInputStream(files[i]);
            ZipEntry entry = new ZipEntry(files[i].getPath().substring(base.getPath().length() + 1));
            zos.putNextEntry(entry);
            while (-1 != (read = in.read(buffer))) {
                zos.write(buffer, 0, read);
            }
            in.close();
        }
    }
}

From source file:Main.java

public static void deleteFilesStartingWith(String string) {
    File specificFile = new File(string);
    File pFile = specificFile.getParentFile();
    if (pFile != null) {
        for (File f : pFile.listFiles()) {
            if (f.getName().startsWith(specificFile.getName())) {
                f.delete();/*w  ww .  j a va  2 s . co m*/
            }
        }
    }
}

From source file:Main.java

public static int getFolderSize(String relativePath) {
    int fileLength = 0;
    //      File dir = new File(path);
    File dir = creatSDDir(relativePath);
    if (dir.isDirectory()) {
        File[] files = dir.listFiles();
        for (File file : files) {
            fileLength += file.length();
        }//  w w  w.  ja v  a 2  s.  c  o m
    } else {
        return -1;
    }
    return fileLength / 1024;
}

From source file:Main.java

static void deleteFile(File f, boolean toDeleteSelf) {
    if (f.isDirectory()) {
        for (File child : f.listFiles())
            deleteFile(child, true);// w  w  w . ja  va  2s  . com
    }
    if (toDeleteSelf)
        f.delete();
}

From source file:Main.java

public static void deleteFile(File file) {
    if (file.exists()) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File subFile : files) {
                deleteFile(subFile);/*from  w w w  .j a  v  a 2  s.  co  m*/
            }
            file.delete();
        } else {
            file.delete();
        }
    }
}

From source file:edu.duke.cabig.c3pr.rules.repository.RepositoryCleaner.java

/**
 * Recursively empty the directory./* w w  w .j a v  a  2 s .  c  o  m*/
 * 
 * @param path
 */
static public void deleteDirectoryContents(File path) {
    if (path.exists()) {
        File[] files = path.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory())
                deleteDirectoryContents(files[i]);
            files[i].delete();
        }
    }

}

From source file:Main.java

public static void U7ListFiles(String mask, Vector<String> filelist) {
    mask = getSystemPath(mask);/*from w w w .j a v  a2  s. c o m*/
    char sep = '/';
    int split = mask.lastIndexOf(sep);
    String dir, nameMask;
    if (split == -1) {
        dir = ".";
        nameMask = mask;
    } else {
        dir = mask.substring(0, split);
        nameMask = mask.substring(split + 1);
    }
    File folder = new File(dir);
    File[] listOfFiles = folder.listFiles();
    Pattern pattern = Pattern.compile(nameMask);
    for (int i = 0; i < listOfFiles.length; i++) {
        if (listOfFiles[i].isFile()) {
            String fname = listOfFiles[i].getName();
            if (pattern.matcher(fname).matches())
                filelist.add(dir + sep + fname);
        }
    }
}