{"record":{"id":"73d4a58bb271382c","repo":"stanfordnlp/CoreNLP","slug":"deleting-more-than-100-files-you-should-do-this-m","errorCode":null,"errorMessage":"Deleting more than 100 files; you should do this manually","messagePattern":"Deleting more than 100 files; you should do this manually","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/io/IOUtils.java","lineNumber":2036,"sourceCode":"   *   <li>More than 100 files cannot be removed with this function.</li>\n   *   <li>More than 10GB cannot be removed with this function.</li>\n   * </ul>\n   *\n   * @param file The file or directory to delete.\n   */\n  public static void deleteRecursively(File file) {\n    // Sanity checks\n    if (blockListPathsToRemove.contains(file.getPath())) {\n      throw new IllegalArgumentException(\"You're trying to delete \" + file + \"! I _really_ don't think you want to do that...\");\n    }\n    int count = 0;\n    long size = 0;\n    for (File f : iterFilesRecursive(file)) {\n      count += 1;\n      size += f.length();\n    }\n    if (count > 100) {\n      throw new IllegalArgumentException(\"Deleting more than 100 files; you should do this manually\");\n    }\n    if (size > 10000000000L) {  // 10 GB\n      throw new IllegalArgumentException(\"Deleting more than 10GB; you should do this manually\");\n    }\n    // Do delete\n    if (file.isDirectory()) {\n      File[] children = file.listFiles();\n      if (children != null) {\n        for (File child : children) {\n          deleteRecursively(child);\n        }\n      }\n    }\n    //noinspection ResultOfMethodCallIgnored\n    file.delete();\n  }\n\n  /**","sourceCodeStart":2018,"sourceCodeEnd":2054,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/IOUtils.java#L2018-L2054","documentation":"deleteRecursively counts the files it is about to remove; if more than 100 files would be deleted it throws this IllegalArgumentException, forcing the developer to delete large trees manually rather than by accident.","triggerScenarios":"IOUtils.deleteRecursively on a directory whose recursive file count exceeds 100.","commonSituations":"Cleanup of build output, caches, or dataset directories that grew past 100 files; pointing the deleter at a large project folder instead of a small scratch dir.","solutions":["Delete the directory manually (e.g. rm -rf or Files.walk + delete in your own code) after verifying contents","Split the deletion into smaller batches under 100 files each","Write your own recursive delete without this guard if the bulk deletion is intentional"],"exampleFix":"// before\nIOUtils.deleteRecursively(largeCacheDir); // 10000 files\n// after\njava.nio.file.Files.walk(largeCacheDir.toPath())\n  .sorted(java.util.Comparator.reverseOrder())\n  .forEach(p -> p.toFile().delete());","handlingStrategy":"try-catch","validationCode":"int n = 0; try (var s = Files.walk(dir.toPath())) { n = (int) s.filter(Files::isRegularFile).count(); } if (n > 100) { /* delete manually */ }","typeGuard":null,"tryCatchPattern":"try { IOUtils.deleteRecursively(dir); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"more than 100 files\")) { /* manual or batched deletion */ } else throw e; }","preventionTips":["Count files before deleting large caches","Clean scratch dirs incrementally instead of in one call","Use your own delete helper for bulk cleanup"],"tags":["filesystem","delete","safety-guard"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}