/**
*
* @param path 被移动的文件夹路径
* @param newPath 目标文件夹路径
*/
public static void reNameToFiles(String path, String newPath) {
// 创建 File对象
File file = new File(path);
// 取 文件/文件夹
File files[] = file.listFiles();
// 对象为空 直接返回
if (files == null) {
return;
}
// 目录下文件
if (files.length == 0) {
return;
}
// 存在文件 遍历 判断
for (File f : files) {
// 判断是否为 文件夹
if (f.isDirectory()) {
// 为 文件夹继续遍历
reNameToFiles(f.getAbsolutePath(), newPath);
// 判断是否为 文件
} else if (f.isFile()) {
f.renameTo(new File(newPath + File.separator + f.getName()));
} else {
return;
}
}
}
欢迎大家加入京东淘宝捡垃圾群:698433653