批量修改文件名 本是古典 何须时尚 2024-03-26 21:16 17阅读 0赞 public static void changeFileName(String path)\{ File file = new File(path); if(file.exists())\{ File\[\] files = file.listFiles(); if (null == files || files.length == 0) \{ System.*out*.println("文件夹是空的!"); return; \} else \{ for (File file2 : files) \{ if (file2.isDirectory()) \{ *changeFileName*(file2.getAbsolutePath()); \} else \{ System.*out*.println("文件:" + file2.getAbsolutePath()); String filePath = file2.getAbsolutePath(); String fileName = filePath.substring(0,filePath.lastIndexOf("\\\\"))+"\\\\1"+file2.getName(); File oriFile = new File(filePath); System.*out*.println("新文件名:" + fileName); boolean b = oriFile.renameTo(new File(fileName)); System.*out*.println(b); \} \} \} \}else\{ System.*out*.println("该路径不存在"); \} \}
还没有评论,来说两句吧...