Android File Delete deleteFiles(File file)

Here you can find the source of deleteFiles(File file)

Description

delete Files

Declaration

public static boolean deleteFiles(File file) 

Method Source Code

//package com.java2s;

import java.io.File;

public class Main {
    public static boolean deleteFiles(File file) {
        return deleteFiles(file, ".*");
    }//from  w w w. j a v a  2s.c  om

    /**
     * recursively delete all sub files which matches regular expression
     * @param file
     * @param regex
     * @return
     */
    public static boolean deleteFiles(File file, String regex) {
        if (!file.exists())
            return true;
        // recursively traversal all sub files
        if (file.isDirectory()) {
            File[] subFiles = file.listFiles();
            for (File subFile : subFiles) {
                if (!deleteFiles(subFile, regex))
                    return false;
            }
        } else if (file.getName().matches(regex))
            return file.delete();
        return true;
    }
}

Related

  1. deleteFile(String path)
  2. deleteFile(String path)
  3. deleteFile(String path)
  4. deleteFile(String strSrc)
  5. deleteFileOnly(String path)
  6. deleteFiles(File file, String regex)
  7. deleteFilesRecursive(File src)
  8. deleteFolder(File targetFolder)
  9. deleteFolders(File dir)