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:Main.java

public static List grabFiles() {
    List<String> tFileList = new ArrayList<String>();
    String p = Environment.getExternalStorageDirectory().getAbsolutePath() + "/nexsight/";
    File f = new File(p);

    Log.d(TAG, "Read from " + p);
    File[] files = f.listFiles();
    files = flipArray(files);// w  w  w.  j  av a  2  s .c om
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            tFileList.add(file.getPath());
        }
    } else {
        Log.w(TAG, "nothing found in " + p);
    }

    return tFileList;
}

From source file:de.netallied.functionblock.converter.java2java.util.Directory.java

/**
 *
 *///  w w  w . j  a v  a  2  s . com
public static ArrayList getAllDirs(File folder, boolean recursive) {
    ArrayList list = new ArrayList();
    File[] files = folder.listFiles();
    if (files == null)
        return list;
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            list.add(files[i]);
            if (recursive)
                list.addAll(getAllDirs(files[i], recursive));
        }
    }
    return list;
}

From source file:Main.java

public static void DeleteRecursive(File fileOrDirectory) {
    boolean bool;
    if (fileOrDirectory.isDirectory())
        for (File child : fileOrDirectory.listFiles()) {
            bool = child.delete();//from   w  ww .j  a v  a  2  s . co  m
            System.out.println(" deleted folder contents > result : " + bool);
            DeleteRecursive(child);
        }
    bool = fileOrDirectory.delete();
    System.out.println(" deleted folder > result : " + bool);
}

From source file:Main.java

private static void addFiles(File root, Vector<String> files) {
    if (root == null)
        return;/*from   w w  w  .  ja va 2s .c  o m*/
    File[] listFiles = root.listFiles();
    if (listFiles == null)
        return;
    for (File f : listFiles) {

        if (f.isDirectory())
            addFiles(f, files);
        else if (f.getName().endsWith(".pfy"))
            files.add(f.getAbsolutePath());

    }

}

From source file:Main.java

public static void deleteFile(File file) {
    if (file.exists()) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File file2 : files) {
                if (file2.isDirectory()) {
                    deleteFile(file2);// w  ww .java  2s  . c o m
                } else {
                    file2.deleteOnExit();
                }
            }
        }
        file.deleteOnExit();
    }
}

From source file:Main.java

public static List<String> getSharedPreferenceTags(Context context) {
    ArrayList<String> tags = new ArrayList<String>();

    String rootPath = context.getApplicationInfo().dataDir + "/shared_prefs";
    File root = new File(rootPath);
    if (root.exists()) {
        for (File file : root.listFiles()) {
            String fileName = file.getName();
            if (fileName.endsWith(PREFS_SUFFIX)) {
                tags.add(fileName.substring(0, fileName.length() - PREFS_SUFFIX.length()));
            }/*  w ww  . ja v a2 s  .c o m*/
        }
    }

    Collections.sort(tags);

    return tags;
}

From source file:fr.tpt.atlanalyser.tests.generic.GenericExecTest.java

public static Collection<File[]> enumerateModels(String baseDir) {
    File inputModelsDir = new File(baseDir, "InputModels");
    File[] inputModels = inputModelsDir.listFiles();
    List<File[]> result = new ArrayList<File[]>();
    for (File file : inputModels) {
        result.add(new File[] { file });
    }//ww  w. java2 s .c o m
    return result;
}

From source file:muffinc.yafdivj.helper.FeretHandler.java

public static void moveToHumans() {
    File file = new File(NEW_FOLDER);

    for (File file1 : file.listFiles()) {
        if (file1.isDirectory()) {
            for (File file2 : file1.listFiles(((FileFilter) new RegexFileFilter("\\w{10}d.*")))) {

                try {
                    String newFolder = "/Users/Meth/Documents/FROG/src/test/resources/Humans/" + "H_"
                            + file2.getName().substring(1, 5) + "/";

                    File file3 = new File(newFolder);

                    if (!file3.exists()) {
                        file3.mkdirs();//from w  w  w  .ja  v  a  2 s.c  om
                    }

                    Files.copy(file2.toPath(), new File(newFolder + file2.getName()).toPath());

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

From source file:Main.java

public static void deleteDir(File dir) {
    if (!dir.exists())
        return;/*from www . j a va  2s . c  om*/
    if (dir.isDirectory()) {
        File[] files = dir.listFiles();
        for (File f : files) {
            deleteDir(f);
        }
        dir.delete();
    } else
        dir.delete();
}

From source file:Main.java

public static void deleteSinglePicture(Context ctx, String path) {
    String params[] = new String[] { path };
    ctx.getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            MediaStore.Images.Media.DATA + " LIKE ?", params);
    File file = new File(path);
    File pFile = file.getParentFile();
    if (pFile != null && pFile.isDirectory()) {
        File files[] = pFile.listFiles();
        if (files == null || files.length == 0) {
            pFile.delete();//from  w  w  w. jav  a 2s  . c o  m
        }
    }
}