コード例 #1
0
ファイル: File.java プロジェクト: talentkimi/kimi
 /**
  * Deletes this file and if it is a directory, recursively deletes all files and subdirectories!
  */
 public void deleteAll() {
   File[] files = listFiles(false);
   if (files != null) {
     for (int i = 0; i < files.length; i++) {
       File file = (File) files[i];
       file.deleteAll();
     }
   }
   delete();
 }
コード例 #2
0
ファイル: File.java プロジェクト: talentkimi/kimi
  /**
   * Adds files from the given directory into the list.
   *
   * @param list the file list.
   * @param dir the directory.
   * @param recursive true to list files recursively.
   * @param filter the filter to use.
   */
  private void addFilesToList(UtilList list, File dir, boolean recursive, FileFilter filter) {
    String[] filenames = dir.list();
    for (int i = 0; i < filenames.length; i++) {
      File file = (File) newFile(dir, filenames[i]);

      // Recursive
      if (recursive) {
        if (file.isDirectory()) {
          addFilesToList(list, file, recursive, filter);
        }
      }

      // Filter
      if (filter != null) {
        if (!filter.accept(file)) {
          continue;
        }
      }

      // Add
      list.add(file);
    }
  }