大佬教程收集整理的这篇文章主要介绍了windows文件夹嵌套太多,导致无法删除的解决方法,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
import java.io.File; public class deleteUtils { public static void main(String[] args) { File dir = new File("D:\\code\\NCE\\Spliter_NCE"); renameDirRecursively(dir); System.out.println("renameDirRecursively success"); deleteRecursively(dir); System.out.println("deleteRecursively success"); } private static void renameDirRecursively(File dir) { File[] listFiles = dir.listFiles(); if (listFiles != null) { int subIndex = 0; for (File file : listFiles) { Boolean isDir = file.isDirectory(); StringBuilder afterName = new StringBuilder(); subIndex = renameFile(file,subIndex,afterName); if (isDir) { renameDirRecursively(new File(afterName.toString())); } } } } private static int renameFile(File file,int index,StringBuilder afterName) { String newName = file.getParent() + File.separator + index; if (afterName != null) { afterName.append(newName); } if (newName.equals(file.getAbsolutePath())) { return index + 1; } Boolean success = file.renameTo(new File(newName)); if (success) { return index + 1; } else { return renameFile(file,index + 1,afterName); } } private static void deleteRecursively(File filE) { if (file.isDirectory()) { File[] listFiles = file.listFiles(); if (listFiles != null) { for (File subFile : listFiles) { deleteRecursively(subFilE); } } file.delete(); } else { file.delete(); } } }
以上是大佬教程为你收集整理的windows文件夹嵌套太多,导致无法删除的解决方法全部内容,希望文章能够帮你解决windows文件夹嵌套太多,导致无法删除的解决方法所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。