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:eu.planets_project.services.utils.test.FileAccess.java

private static void index(File root, Map<String, File> map) {
    String[] list = root.list();/* w  w  w  .j a v  a 2  s .c  om*/
    for (String name : list) {
        File f = new File(root, name);
        if (f.isDirectory() && !f.isHidden()) {
            index(f, map);
        } else if (f.isFile() && !f.isHidden()) {
            map.put(FilenameUtils.getExtension(f.getName()).toLowerCase(), f);
        }
    }
}

From source file:Main.java

public static void deleteSharedPreferences(Context context) {
    try {// w  w w .  j a  va2 s .  c o  m
        Context appContext = context.getApplicationContext();
        ApplicationInfo info = appContext.getPackageManager().getApplicationInfo(appContext.getPackageName(),
                0);
        String dirPath = info.dataDir + File.separator + "shared_prefs" + File.separator;
        File dir = new File(dirPath);
        if (dir.exists() && dir.isDirectory()) {
            String[] list = dir.list();
            int size = list.length;
            for (int i = 0; i < size; i++) {
                new File(dirPath + list[i]).delete();
            }
        } else {
            //Log.d("AAA", "NO FILE or NOT DIR");
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static void dirChecker(String destinationPath) {
    File f = new File(destinationPath);
    if (!f.isDirectory()) {
        f.mkdirs();//from  w w  w .ja  va2 s . com
    }
}

From source file:Main.java

@SuppressWarnings("WeakerAccess")
public static boolean cleanDir(File dir) {
    if (dir == null || !dir.exists() || !dir.isDirectory()) {
        return true;
    }/* w w  w .j a  va2  s .co m*/

    File[] files = dir.listFiles();
    boolean cleanSuccess = true;
    if (files != null) {
        for (File tempFile : files) {
            if (tempFile.isDirectory()) {
                cleanSuccess &= cleanDir(tempFile);
            }
            cleanSuccess &= tempFile.delete();
        }
    }
    return cleanSuccess;
}

From source file:Main.java

private static boolean checkFsWritable() {
    // Create a temporary file to see whether a volume is really writeable.
    // It's important not to put it in the root directory which may have a
    // limit on the number of files.
    String directoryName = Environment.getExternalStorageDirectory().toString() + "/DCIM";
    File directory = new File(directoryName);
    if (!directory.isDirectory()) {
        if (!directory.mkdirs()) {
            return false;
        }/* w ww. j a v a 2 s . com*/
    }
    File f = new File(directoryName, ".probe");
    try {
        // Remove stale file if any
        if (f.exists()) {
            f.delete();
        }
        if (!f.createNewFile()) {
            return false;
        }
        f.delete();
        return true;
    } catch (IOException ex) {
        return false;
    }
}

From source file:Main.java

public static void deleteFiles(File file) {
    try {//from ww  w .  j av a  2s . co m
        if (file.exists()) {
            if (file.isDirectory()) {
                File[] childFiles = file.listFiles();
                for (File f : childFiles) {
                    deleteFiles(f);
                }
            } else {
                file.delete();
            }
        }
    } catch (Exception e) {
    }
}

From source file:Main.java

/**
 * recursively delete/*from   w  w  w  .  j  av a2s  . c  o  m*/
 *
 * @param dir
 * @throws java.io.IOException
 */
public static void deleteDirectoryRecursively(File dir) throws IOException {
    File[] files = dir.listFiles();
    if (files == null) {
        throw new IllegalArgumentException("not a directory: " + dir);
    }
    for (File file : files) {
        if (file.isDirectory()) {
            deleteDirectoryRecursively(file);
        }
        if (!file.delete()) {
            throw new IOException("failed to delete file: " + file);
        }
    }
}

From source file:Main.java

public static void deleteFile(String filePath) {
    File file = new File(filePath);
    if (file.exists()) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    deleteFile(files[i].getPath());
                } else {
                    files[i].delete();/*from w ww  .j  av  a  2  s .  c  o  m*/
                }
            }
        }
        file.delete();
    }
}

From source file:es.urjc.mctwp.bbeans.research.SessionUtils.java

public static void cleanFolder(File folder) {

    if ((folder != null) && (folder.isDirectory())) {
        try {//from  www.  j  a v a  2s  .  c  o  m
            FileUtils.cleanDirectory(folder);
        } catch (IOException ioe) {
            logger.error("Could not clean user temp directory");
            //throw ioe;
        }
    }
}

From source file:Main.java

public static void notifyFileSystemChanged(String path, Context mContext) {
    if (path == null)
        return;//  w w  w.  j  a  v  a  2s .com
    final File f = new File(path);
    final Intent intent;
    if (f.isDirectory()) {
        intent = new Intent(Intent.ACTION_MEDIA_MOUNTED);
        intent.setClassName("com.android.providers.media", "com.android.providers.media.MediaScannerReceiver");
        intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory()));

    } else {
        intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        intent.setData(Uri.fromFile(new File(path)));

    }
    mContext.sendBroadcast(intent);
}