title: Delete All file and sub-folder Except the main folder
body: <p>I am new android app</p>
  
  <p>In some part of my app , I need to delete all file and sub-folder in /data/data/PACkAGE_NAME/ but keep the main folder</p>
  
  <p>i have root accesses also ! and shell commend </p>
  
  <p>i Have used  two methods but at both of them the package folder has deleted</p>
  
  <p>method 1 :</p>
  
  <pre><code>public static void ClearData(String Dir) {
  
      String sCommand = "rm -rf " + Dir + "*";
      Command command = new Command(0,sCommand);
  
      try {
  
          RootTools.getShell(true).add(command);
  
      } catch (IOException e) {
          e.printStackTrace();
      } catch (TimeoutException e) {
          e.printStackTrace();
      } catch (RootDeniedException e) {
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>method 2 :</p>
  
  <pre><code>public static boolean deleteDir(File dir) {
  
      if (dir.isDirectory()) {
          String[] children = dir.list();
          for (int i=0; i&lt;children.length; i++) {
              boolean  success = deleteDir(new File(dir, children[i]));
              if (!success) {
                  return false;
              }
          }
      }
  
      // The directory is now empty so delete it
  
  
      return dir.delete();
  }
  </code></pre>
  
  <p>tnx</p>
  
  <p>EDIT : I found solution :</p>
  
  <p>public static void ClearData(String Dir) {</p>
  
  <pre><code>    String sCommand = "rm -rf " + Dir + "/*";
      Command command = new Command(0,sCommand);
  
      try {
  
          RootTools.getShell(true).add(command);
  
      } catch (IOException e) {
          e.printStackTrace();
      } catch (TimeoutException e) {
          e.printStackTrace();
      } catch (RootDeniedException e) {
          e.printStackTrace();
      }
  
  }
  </code></pre>