public static boolean deleteFiles(Context context,final String path,Handler handler,long mTotalFileNum){
  boolean ret=true;
  File f=new File(path);
  if (!f.isDirectory()) {
    ret=f.delete();
    sendProgressMessage(handler,mTotalFileNum);
    return ret;
  }
  Stack<File> stack=new Stack<File>();
  Stack<File> stackDir=new Stack<File>();
  stack.push(f);
  stackDir.push(f);
  while (!stack.isEmpty() && (null != (f=stack.pop()))) {
    for (    File file : f.listFiles()) {
      if (file.isDirectory()) {
        stack.push(file);
        stackDir.push(file);
      }
 else {
        ret=file.delete();
        sendProgressMessage(handler,mTotalFileNum);
      }
      if (ret == false)       return false;
    }
  }
  while (!stackDir.isEmpty() && (null != (f=stackDir.pop()))) {
    ret=f.delete();
    if (ret == false)     return false;
  }
  return ret;
}

public static boolean deleteFiles ( Context context , final String path , Handler handler , long mTotalFileNum ) { boolean ret = true ; File f = new File ( path ) ; if ( ! f . isDirectory ( ) ) { ret = f . delete ( ) ; sendProgressMessage ( handler , mTotalFileNum ) ; return ret ; } Stack < File > stack = new Stack < File > ( ) ; Stack < File > stackDir = new Stack < File > ( ) ; stack . push ( f ) ; stackDir . push ( f ) ; while ( ! stack . isEmpty ( ) && ( null != ( f = stack . pop ( ) ) ) ) { for ( File file : f . listFiles ( ) ) { if ( file . isDirectory ( ) ) { stack . push ( file ) ; stackDir . push ( file ) ; } else { ret = file . delete ( ) ; sendProgressMessage ( handler , mTotalFileNum ) ; } if ( ret == false ) return false ; } } while ( ! stackDir . isEmpty ( ) && ( null != ( f = stackDir . pop ( ) ) ) ) { ret = f . delete ( ) ; if ( ret == false ) return false ; } return ret ; }
delete files or folders
